After some trial and error, I got it working. However, during some of the trial and error iterations I wasn’t sure what I was doing. So I had to go back to lecture notes and work through the dimensions (shape) of the various vectors involved, specially in multipication (dot product) operations. Seems a lot of work (which is useful for learning). Is there a better way than to be paying attention or counting the dimensions and see if they balance/behave according to Linear Algebra rules?
Hi @dds ,
It is really a good question! While doing with np.dot(), for instance np.dot(A, B), you can put print(A.shape) and print(B.shape). So if np.dot() doesn’t work, you can look at the shape of A and B and figure out why.
Hi @Phuc_Kien_Bui
Confusion arises when say both A and B are dim (1, m). Suppose you want to take np.dot(A, B). According to the numpy documentation it should do elementwise multiplication and then add the term (just as expected from our basic Physics 101).
Example:
import numpy as np
A = np.array([1, 2])
print( "A shape: " + str(A.shape))
However, in Exercise 5 had to take transpose of B to make the dot work correctly np.dot(A, B.T). Though in the example above np.dot(A, B), np.dot(A, B.T) , np.dot(A.T, B) all give same result. It is relevant when computing np.dot (w.T, X) - both w and X have smae shape (m, 1).