How does coo_matrix((data, (i, j)), [shape=(M, N)]) work?
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
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 <mviljamaa@kapsi.fi> 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 SciPy-User@python.org https://mail.python.org/mailman/listinfo/scipy-user
participants (2)
-
Gregory Lee -
Matti Viljamaa