In the practice lab of week 1, part 2.6
x = X[0].reshape(-1,1) # column vector (400,1)
z1 = np.matmul(x.T,W1) + b1 # (1,400)(400,25) = (1,25)
a1 = sigmoid(z1)
print(a1.shape)
May I ask why we need to reshape the vector x to a column vector, and then we applied matmul on its transpose. Why didn’t we just use its own X[0] inside the matmul like this:
z1 = np.matmul(X[0],W1) + b1
For matmul to work, the first matrix must have the same number of columns as the second matrix has rows.
Therefore, x is transposed to meet this requirement.
But isn’t the X[0] matrix has the same number of column as the second matrix? At first, X[0] was a row vector (1,400) right? And then it got applied reshape on it to a column vector (400,1), and once again it got transposed one more time.
Since the 2.6 section of the assignment is optional, you could try experimenting within that cell by printing the shape of X[0] to see if it gives the shape (1, 400).
Also, what will be the resulting shape of a1 if you pass X[0] directly into np.matmul?