Homework Q1

#1

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
#2

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

#3

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

#4

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

#5

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
#6

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.

#7

I thought we were supposed to use dot products?

#8

FYI my part 4 “only” took 5000 secs LOL

#9

Yeah my part took 4000 seconds lol

#10

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

#11

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?

#12

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

#13

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

#14

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.

#15

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