I've been recently dealing with sparse matrices. My aim is to somehow convert an adjacency list for a graph into the CSR format, defined here: http://devblogs.nvidia.com/parallelforall/wp-content/uploads/2014/07/CSR.png.
One possible option I see, is that I simply first construct a NumPy matrix and convert it using scipy.sparse.csr_matrix
. The problem is, that the CSR in SciPy is somewhat different to the one discussed in the link. My question is, is this just a discrepancy, and I need to write my own parser, or can SciPy in fact convert into CSR defined in the link.
A bit more about the problem, let's say I have a matrix:
matrix([[1, 1, 0],
[0, 0, 1],
[1, 0, 1]])
CSR format for this consists of two arrays, Column(C) and row(R). And i strive for looks like:
C: [0,1,2,0,2]
R: [0,2,3,5]
SciPy returns the:
(0, 0) 1
(0, 1) 1
(1, 2) 1
(2, 0) 1
(2, 2) 1
where second column is the same as my C, yet this is to my understanding the COO format, not the CSR. (this was done using csr_matrix(adjacency_matrix)
function).