Re: How does coo_matrix((data, (i, j)), [shape=(M, N)]) work?

Gregory Lee <[email protected]>
Newsgroups gmane.comp.python.scientific.user
Message-ID <CAJR3sXcdwUJ-wrewYYfh-6tJhG4WPFQ5brd7OKC4_8=XLriyaQ@mail.gmail.com>
Hi Matti,

data, i and j are all 1d arrays of matching length.  The order of data
doesn't matter because the corresponding entries in i and j indicate the
row and column indices where the data is stored within the sparse MxN
matrix.

A minimal example that reversing the order of data, i and j gives the same
matrix:

from scipy.sparse import coo_matrix

coo_matrix(([2, 3], ([0, 1], [2, 1])), shape=(3, 3)).todense()
matrix([[0, 0, 2],
        [0, 3, 0],
        [0, 0, 0]])

coo_matrix(([3, 2], ([1, 0], [1, 2])), shape=(3, 3)).todense()
matrix([[0, 0, 2],
        [0, 3, 0],
        [0, 0, 0]])


On Tue, Apr 17, 2018 at 3:53 PM, Matti Viljamaa <[email protected]> wrote:

> I’m confused about the following instantiation of coo_matrix:
>
> coo_matrix((data, (i, j)), [shape=(M, N)])
>
> data contains the entries of the matrix in any order. Why can they be in
> any order? Is data a vector or a matrix?
>
> What are i,j used for?
>
> BR, Matti
>
> _______________________________________________
> SciPy-User mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/scipy-user
>
>

_______________________________________________
SciPy-User mailing list
[email protected]
https://mail.python.org/mailman/listinfo/scipy-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.