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

﹥>﹥吖頭↗ 提交于 2019-12-22 05:33:20

问题


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!)


回答1:


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



来源:https://stackoverflow.com/questions/40809503/python-numpy-typeerror-ufunc-isfinite-not-supported-for-the-input-types

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!