2024-06-02 17:26:22 发布
网友
我有一个稀疏数组,比如:
from scipy import sparse a = sparse.lil_matrix((2,3),) a[0] = [1, 2, 3] a[1, 2] = 5
所以它看起来像:
我在想-有没有一种简单的方法来翻转行(类似于numpy.fliplr等价物)。。。所以我得到的输出是:
numpy.fliplr
(0, 0) 3.0 (0, 1) 2.0 (0, 2) 1.0 (1, 0) 5.0
一种方法是将数组转换为csr格式,然后操作行索引:
csr
from scipy import sparse a = sparse.lil_matrix((2,3),) a[0] = [1, 2, 3] a[1, 2] = 5 a = a.tocsr() a.indices = -a.indices + a.shape[1] - 1 print(a)
收益率
您可以执行多索引分配:
ii = [2,1,0,3] a[:,1] = a[ii,:]
其中ii是必须以某种方式创建的索引数组。在
ii
一种方法是将数组转换为
csr
格式,然后操作行索引:收益率
^{pr2}$您可以执行多索引分配:
其中
ii
是必须以某种方式创建的索引数组。在相关问题 更多 >
编程相关推荐