[Numpy-discussion] Unexplained nans in matrix multiplication

Dag Sverre Seljebotn dagss at student.matnat.uio.no
Thu Oct 29 09:26:44 EDT 2009


I'm getting (to me( very mysterious NaNs when doing matrix 
multiplication with certain (randomly generated) data:

In [52]: a.shape, b.shape, i, j
Out[52]: ((22, 1000), (1000, 22), 0, 16)

In [53]: np.dot(a, b)[i,j]
Out[53]: (31.322778824758661+nan*j)

In [54]: np.dot(a[i,:], b[:,j])
Out[54]: (31.322778824758657+6.5017268607881213j)

In [55]: np.any(np.isnan(a)), np.any(np.isnan(b))
Out[55]: (False, False)

In [63]: np.max(np.abs(np.vstack((a.real, a.imag, b.real.T, b.imag.T))))
Out[63]: 4.0744710639852633

dtype is complex128. Is this a bug? Should I start looking in NumPy, 
ATLAS (Sage-compiled), the C compiler, the Fortran compiler...*shrug*

I realize that matmul doesn't have to happen via naive vector dot 
products, but certainly one shouldn't hit Inf anywhere anyway?

Dag Sverre



More information about the NumPy-Discussion mailing list