Recently I got a problem when learning Python numpy. Actually I was testing a self-defined function on a remote server, and this function uses numpy.linalg.eig:
import numpy
from numpy import *
def myfun(xAr,yAr) #xAr, yAr are Matrices
for i in xrange(xAr.shape[1]):
Mat=xAr.T*yAr*yAr.T*xAr
val,vec=linalg.eig(Mat)
# and so on...
and the test gives error report " line 1088, in eig: Array must not contain infs or NaNs".
Thus I tried to delete those columns containing NaNs or Infs, and my code is:
def myfun(xAr,yAr)
id1=isfinite(sum(xAr,axis=1))
id2=isfinite(sum(yAr,axis=1))
xAr=xAr[id1&id2]
yAr=yAr[id1&id2]
for i in xrange(xArr.shape[1]):
Mat=xAr.T*yAr*yAr.T*xAr
val,vec=linalg.eig(Mat)
# and so on...
However the same error arose again.
I don't know the exact data values for this testing, as this test is on a remote server and original data values are forbidden to show. What I know is the data is a matrix containing NaNs and Infs.
Could anyone give me some suggestions why isfinite fails to work here, or where I did wrong for deleting these NaNs and Infs?