Question: Compressed Sparse Row Format This is similar to the COO format excpet that it is much more compact and takes up less storage. Look at
Compressed Sparse Row Format
This is similar to the COO format excpet that it is much more compact and takes up less storage. Look at the picture below to understand more about this representation

Exercise 8 (3 points). Now create a CSR data structure, again using native Python lists. Name your output CSR lists csr_ptrs, csr_inds, and csr_vals.
It's easiest to start with the COO representation. We've given you some starter code. Unlike most of the exercises, instead of creating a function, you have to compute csr_ptrs here.
from operator import itemgetter C = sorted(zip(coo_rows, coo_cols, coo_vals), key=itemgetter(0)) nnz = len(C) assert nnz >= 1
assert (C[-1][0] + 1) == num_verts # Why? csr_inds = [j for _, j, _ in C] csr_vals = [a_ij for _, _, a_ij in C]
# Your task: Compute `csr_ptrs` ### ### YOUR CODE HERE ### csr_ptrs=[0,] compareble = 0 count = 0 for i,_,_ in C:
if i != compareble: csr_ptrs.append(count) print(csr_ptrs) compareble = i count += 1
I thought my logic was correct, but my code runs so slow, which takes forever to run. How can I make it run faster?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
