Python Numpy TypeError: ufunc 'isfinite' not supported for the input types
82,580
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
Related videos on Youtube
Author by
swabygw
Updated on July 09, 2022Comments
-
swabygw almost 2 years
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:
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!)
-
jmd_dk over 7 yearsWhat is the
dtype
ogcovMat
? -
swabygw over 7 yearsAs in the picture, it shows "object" (36 rows, 36 columns).
-
jmd_dk over 7 yearsAh, that's the
dtype
. Well that might very well be your problem. Try usingnp.array(covMat, dtype=float)
. Does that convertion give you an error?
-
-
Naveen Srikanth almost 4 yearsThis has helped me as well. I was using shap and I was getting this type conversion error. I had check one of my attribute was object changed to float and it worked . Thanks for solution