问题很简单:假设我有一个来自 scipy 稀疏矩阵 M(100,000X500,000)的给定行 r,我想在 M 矩阵中找到它的位置/索引?我怎样才能有效地做到这一点?
目前我正在尝试以下方式,但速度非常慢。
offset = 500
begin = 0
end = begin + offset
row = row.todense() #convert sparse to dense
while 1:
sub_M = M[begin:end,:].todense() #M matrix is too big that its dense cannot fit memory
labels=np.all(row == sub_M, axis=1) # here we find row in the sub set of M, but in a dense representation
begin = end
end = end + offset
if (end - offset) == M.shape[0]:
break
elif end > M.shape[0]:
end = M.shape[0]