Question
Hi I am trying to convert a sparse matrix COO format row list to CSR format row ptr in an efficient way because the matrix
Hi
I am trying to convert a sparse matrix COO format row list to CSR format row ptr in an efficient way because the matrix has a millions row.
For example:
coo_row_list=[0,0,0,1,1,1,2,2,2,2,3,3,3,3,4,4,4,5,5,5,6,6]
Output:
csr_pt=[0,3,6,10,14,17,20,22]
which 0 is the index of first "0", 3 is the first index of "1", 6 is the 2nd index of "2", etc
I wrote the below code, it works on the example, however, when I run it on the actual matrix (a million number), it got stuck and fail. Do you have an more efficient way?
A_coo_row=[0,0,0,1,1,1,2,2,2,2,3,3,3,3,4,4,4,5,5,5,6,6]
A_set=set(A_coo_row)
for i in A_set:
d[i]=A_coo_row.count(i)
csr_ptrs=[0]
index=0
for key in d.keys():
index+=d[key]
csr_ptrs.append(index)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started