python sparse csr matrix: how to serialize it

Viewed 928

I have a csr_matrix, which is constructed as follows:

from scipy.sparse import csr_matrix
import numpy as np
row = np.array([0, 0, 1, 2, 2, 2])
col = np.array([0, 2, 2, 0, 1, 2])
data = np.array([1, 2, 3, 4, 5, 6])
a = csr_matrix((data, (row, col)), shape=(3, 3))

Now to serialize (and for some other purpose), I want to get row, col and data information from matrix "a".

Kindly tell me an easy way to achieve it.

Edit: a.data will give me the data, but how to get row and col informaion

1 Answers
Related