Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...