Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
def classify(self, texts):
vectors = self.dictionary.feature_vectors(texts)
predictions = self.svm.decision_function(vectors)
predictions = np.transpose(predictions)[0]
predictions = predictions / 2 + 0.5
predictions[predictions > 1] = 1
predictions[predictions < 0] = 0
return predictions
The error:
TypeError: 'numpy.float64' object does not support item assignment
occurs on the following line:
predictions[predictions > 1] = 1
Does anyone has an idea of solving this problem? Thanks!
–
–
–
–
Try this testing code and pay attention to np.array([1,2,3], dtype=np.float64)
.
It seems self.svm.decision_function(vectors) returns 1d array instead of 2d.
If you replace [1,2,3] to [[1,2,3], [4,5,6]] everything will be ok.
import numpy as np
predictions = np.array([1,2,3], dtype=np.float64)
predictions = np.transpose(predictions)[0]
predictions = predictions / 2 + 0.5
predictions[predictions > 1] = 1
predictions[predictions < 0] = 0
Output:
Traceback (most recent call last):
File "D:\temp\test.py", line 7, in <module>
predictions[predictions > 1] = 1
TypeError: 'numpy.float64' object does not support item assignment
So, what your vectors are?
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.