Hi all,

I completed the week 2 quiz but am still wondering how we determine when to transpose a matrix when going from a for loop implementation to a vectorized implementation.

For example:

a = np.random.randn(3,4)

b = np.random.randn(4,1)

c = a+b

and we create the for loop below

for i in range(3):

for j in range(4):

c[i][j]=a[i][j] + b[j]

I know that we transpose b when we create a vectorized implementation, but why is that? Does it have something to do with matrix multiplication or for loops that I’m missing?

Thanks a ton!