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
錯誤:類型錯誤: 'numpy.float64' 對象不支持項目分配
TypeError: 'numpy.float64' object does not support item assignment
發生在下面一行:
predictions[predictions > 1] = 1
沒有人有解決這個的想法問題?謝謝!
在哪一行發生錯誤?你應該總是從Python發佈你的「追溯」。 –
當您將'predictions = np.transpose(predictions)[0]'分配給''時,您已將'predictions'設爲標量。因此,當您嘗試進一步向下執行2到3行時,您無法再索引它。你想達到什麼目的?! –
抱歉,此行「預測[預測> 1] = 1」: TypeError:'numpy.float64'對象不支持項目分配 – chen