Homework Q1

I’m having a hard time understanding what is being asked in Q1.3 & 1.4 of homework 1:

  1. Compute 𝐶=𝐴𝐵, treating 𝐴 as a matrix but computing the result for each column of 𝐵 one at a time.
  2. Compute 𝐶=𝐴𝐵, treating 𝐴 and 𝐵 as collections of vectors.

How do we “treat A as a matrix” or a “collection of vectors”?

1 Like

A is itself a matrix but you can also look at it as a collection of column vectors or row vectors.

Part 4 is taking an insanely long amount of time to run, can we do this experiment with matrices of smaller sizes?

Mine finished in about 140 seconds. I think it is correct.

Is there a better way to loop over the vectors? I’m using range() and it’s taking super long.
And using nd.arange() kills my kernel for some reason.

1 Like

I looped over too using outer products. It killed my kernel when I first implemented it but then after I fixed something it can compute in 2 minutes.

I thought we were supposed to use dot products?

FYI my part 4 “only” took 5000 secs LOL

Yeah my part took 4000 seconds lol

By outer product I meant uv.T using dot product.

Feel like I’m doing something wrong for parts 3 and 4 while iterating through the columns for vector dot products… about how long should each run for?

Mine ran for 3000 seconds for part 4. I can’t seem to find a better solution though.

:frowning: my kernel keeps dying after around 10min, how did you end up getting around that?

Are you using arange() for your loops? They have a strange tendency of killing kernels. I switched to the native range() and was fine after that. I have no idea why though.

The main point is to get the message across that it takes a stupidly long time not to use efficient vectorization. As a side effect, you’ll never write inefficient code that doesn’t use acceleration again :slight_smile:

1 Like