【发布时间】:2018-11-26 16:15:20
【问题描述】:
我有 coo_matrix X 和索引 trn_idx,我想通过它们访问那个 maxtrix
print (type(X ), X.shape)
print (type(trn_idx), trn_idx.shape)
<class 'scipy.sparse.coo.coo_matrix'> (1503424, 2795253)
<class 'numpy.ndarray'> (1202739,)
这样调用:
X[trn_idx]
TypeError: only integer scalar arrays can be converted to a scalar index
无论哪种方式:
X[trn_idx.astype(int)] #same error
如何按索引访问?
【问题讨论】:
-
X[trn_idx.astype(int)]? -
@Divakar ops,拼写错误
-
给我们重现问题的最小示例案例?
-
转换为其他稀疏格式之一。
X.tocsr()[idx,:]。coo格式没有实现索引。这应该在文档中很清楚。
标签: python python-3.x numpy scipy sparse-matrix