【发布时间】:2017-12-29 08:50:50
【问题描述】:
a、b 是 1D numpy ndarray,大小与整数数据类型相同。
C 是一个二维的scipy.sparse.lil_matrix。
如果索引[a, b] 包含重复索引,C[a, b] += np.array([1]) 是否总是为 C 的每个唯一索引增加一次 C [a, b]?
文档是否提到了这一点?
例子:
import scipy.sparse as ss
import numpy as np
C = ss.lil_matrix((3,2), dtype=int)
a = np.array([0, 1, 2] * 4)
b = np.array([0, 1] * 6)
C[a, b] += np.array([1])
print(C.todense(), '\n')
C[a, b] += np.array([1])
print(C.todense())
结果:
[[1 1]
[1 1]
[1 1]]
[[2 2]
[2 2]
[2 2]]
【问题讨论】:
标签: python numpy indexing scipy sparse-matrix