【发布时间】:2021-12-30 21:18:09
【问题描述】:
我在 python 中有一个稀疏矩阵 A。我正在浏览我一个朋友的代码,他在他的代码中使用了A[:,i:i+1].toarray().flatten()。就我而言,该程序对他有用。但是,当我尝试使用它时,我得到:
from scipy import sparse
...
diagonals = [[2] * 3, [-1] * (3-1), [-1] * (3-1)]
offsets = [0, 1, -1]
B = sparse.diags(diagonals, offsets)
A = sparse.kronsum(B,B)
...
A[:,i:i+1].toarray().flatten()
例外:
in __getitem__
raise NotImplementedError
NotImplementedError
我的问题,我需要实现什么或如何访问稀疏矩阵的元素。感谢您的帮助。
【问题讨论】:
标签: python scipy sparse-matrix