[SciPy-User] flattened index for Sparse Matrix?
Lutz Maibaum
lutz.maibaum at gmail.com
Thu Nov 4 11:39:52 EDT 2010
On Thu, Nov 4, 2010 at 6:44 AM, braingateway <braingateway at gmail.com> wrote:
> Thanks a lot! Then what about the first question? How could I index the
> sparse matrix as flattened version?
If you want to index only the non-zero matrix elements, you can use
the (for CSR matrices) the data array directly. If you want to index
all matrix elements, I can't think of a better way than to convert an
index i to the two-dimensional matrix coordinates:
a[i / a.shape[1], i % a.shape[1]]
Hope this helps,
Lutz
More information about the SciPy-User
mailing list