我有coo矩阵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,)
这样称呼:
^{pr2}$以这种方式:
X[trn_idx.astype(int)] #same error
如何通过索引访问?在
coo_matrix
类不支持索引。您必须将其转换为不同的稀疏格式。在下面是一个带有小
coo_matrix
的示例:尝试索引
^{pr2}$m
失败:如果将
m
转换为CSR矩阵,则可以使用idx
对其进行索引:如果要进行更多索引,最好将新数组保存在变量中,并根据需要使用它:
试试看这个。在
在通过索引访问之前,您需要转换为密集矩阵。
尝试对稀疏矩阵使用toarray()方法,然后可以通过索引访问。在
相关问题 更多 >
编程相关推荐