gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
TypeError: sparse matrix length is ambiguous; use getnnz() or shape[0] 如何用getnnz()…
- User
TypeError: sparse matrix length is ambiguous; use getnnz() or shape[0] 如何用getnnz() 修改predictions = np.zeros((len(X), len(self.trees)).tocsc(),dtype=int)
- Assistant
可以通过以下方式修改:
-
首先,将创建稀疏矩阵的语句修改为只创建一个空的稀疏矩阵,不指定长度:
predictions = scipy.sparse.csc_matrix((len(X), len(self.trees)), dtype=int) -
然后在需要使用矩阵长度的地方,使用
getnnz()或shape[0]代替len(X):predictions = np.zeros((predictions.shape[0], len(self.trees)), dtype=int)
或
predictions = np.zeros((predictions.getnnz(), len(self.trees)), dtype=int) -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.