Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions