没问题:
>>> t = np.array([[1,1,1,1,1],[2,2,2,2,2],[3,3,3,3,3],[4,4,4,4,4],[5,5,5,5,5]])
>>> x = np.arange(5).reshape((-1,1)); y = np.arange(5)
>>> print (t[[x]],t[[y]])
大问题:
>>> s = scipy.sparse.csr_matrix(t)
>>> print (s[[x]].toarray(),s[[y]].toarray())
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
: :
: :
ValueError: data, indices, and indptr should be rank 1
s.toarray()[[x]]
效果很好,但是由于我的数组太大,因此破坏了我使用稀疏矩阵的全部目的。我已经检查了与一些稀疏矩阵相关联的属性和方法,以获取任何引用高级索引的内容,但没有骰子。有任何想法吗?