Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Numpy TypeError: ufunc 'isfinite' not supported for the input types

Tags:

Here's my code:

def topK(dataMat,sensitivity):     meanVals = np.mean(dataMat, axis=0)     meanRemoved = dataMat - meanVals     covMat = np.cov(meanRemoved, rowvar=0)     eigVals,eigVects = np.linalg.eig(np.mat(covMat)) 

I get the error in the title on the last line above. I suspect has something to do with the datatype, so, here's an image of the variable and datatype from the Variable Explorer in Spyder:

enter image description here

I've tried changing np.linalg.eig(np.mat(covMat)) to np.linalg.eig(np.array(np.mat(covMat))) and to np.linalg.eig(np.array(covMat)), nothing works. Any ideas? (an example would be great!)

like image 845
swabygw Avatar asked Nov 25 '16 16:11

swabygw


1 Answers

Your array has a dtype of object, but this should be some floating point dtype. Use e.g.

covMat = np.array(covMat, dtype=float) 

to convert the dtype

like image 188
jmd_dk Avatar answered Sep 22 '22 13:09

jmd_dk