Zauważyłem niespójne zachowanie w numpy.dot
, gdy zaangażowane są zer i liczby nan
.Błąd Numpy.dot? Niekonsekwentne zachowanie NaN
Czy ktokolwiek może to zrozumieć? Czy to błąd? Czy jest to specyficzne dla funkcji dot
?
Używam numpy v1.6.1, 64bit, działa na Linuksie (również testowane na v1.6.2). Testowałem także na v1.8.0 na Windowsie 32-bitowym (nie mogę stwierdzić, czy różnice wynikają z wersji lub systemu operacyjnego czy arch.).
from numpy import *
0*nan, nan*0
=> (nan, nan) # makes sense
#1
a = array([[0]])
b = array([[nan]])
dot(a, b)
=> array([[ nan]]) # OK
#2 -- adding a value to b. the first value in the result is
# not expected to be affected.
a = array([[0]])
b = array([[nan, 1]])
dot(a, b)
=> array([[ 0., 0.]]) # EXPECTED : array([[ nan, 0.]])
# (also happens in 1.6.2 and 1.8.0)
# Also, as @Bill noted, a*b works as expected, but not dot(a,b)
#3 -- changing a from 0 to 1, the first value in the result is
# not expected to be affected.
a = array([[1]])
b = array([[nan, 1]])
dot(a, b)
=> array([[ nan, 1.]]) # OK
#4 -- changing shape of a, changes nan in result
a = array([[0],[0]])
b = array([[ nan, 1.]])
dot(a, b)
=> array([[ 0., 0.], [ 0., 0.]]) # EXPECTED : array([[ nan, 0.], [ nan, 0.]])
# (works as expected in 1.6.2 and 1.8.0)
Case # 4 wydaje się działać poprawnie w v1.6.2 i v1.8.0, ale nie przypadku # 2 ...
EDIT: @seberg podkreślić, że jest to kwestia blas , więc tutaj jest informacji o instalacji Blas znalazłem uruchamiając from numpy.distutils.system_info import get_info; get_info('blas_opt')
:
1.6.1 linux 64bit
/usr/lib/python2.7/dist-packages/numpy/distutils/system_info.py:1423: UserWarning:
Atlas (http://math-atlas.sourceforge.net/) libraries not found.
Directories to search for the libraries can be specified in the
numpy/distutils/site.cfg file (section [atlas]) or by setting
the ATLAS environment variable.
warnings.warn(AtlasNotFoundError.__doc__)
{'libraries': ['blas'], 'library_dirs': ['/usr/lib'], 'language': 'f77', 'define_macros': [('NO_ATLAS_INFO', 1)]}
1.8.0 windows 32bit (anaconda)
c:\Anaconda\Lib\site-packages\numpy\distutils\system_info.py:1534: UserWarning:
Blas (http://www.netlib.org/blas/) sources not found.
Directories to search for the sources can be specified in the
numpy/distutils/site.cfg file (section [blas_src]) or by setting
the BLAS_SRC environment variable.
warnings.warn(BlasSrcNotFoundError.__doc__)
{}
(ja osobiście nie wiem, co o tym myśleć)
Jest interesujący dla przypadku 2, "a * b" daje pożądany wynik, ale nie ma wartości 'np.dot (a, b)'. – wflynny
Wynik kropki zależy od używanej biblioteki blas. Na przykład widzę to samo z openblas (ale nie z atlasem), więc albo to nie jest określone, albo błąd w bibliotece blas. Mnożenie jest niezwiązane naprawdę ... – seberg
Hmm, spróbuj 'from numpy.distutils.system_info import get_info; get_info ('blas_opt') ' – seberg