Python Numpy TypeError:ufunc' isfinite'输入类型不支持

时间:2016-11-25 16:50:59

标签: python arrays pandas numpy eigenvalue

这是我的代码:

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

我在上面最后一行的标题中收到错误。我怀疑与数据类型有关,所以,这里是Spyder中Variable Explorer的变量和数据类型的图像:

enter image description here

我尝试将 np.linalg.eig(np.mat(covMat))更改为 np.linalg.eig(np.array(np.mat(covMat)) )) np.linalg.eig(np.array(covMat)),没有任何效果。有任何想法吗? (一个例子会很棒!)

1 个答案:

答案 0 :(得分:7)

您的数组的dtypeobject,但这应该是一些浮点dtype。使用例如

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

转换dtype