Week 4 Problem 3 Wrong shape of array X1

Ok I have trouble remembering the code syntax vs math, but I don’t understand the logic behind why none of the below 4 solutions are producing a 5x1 matrix as required.

P = 5x5 matrix
X0 = np.array([[a],[b],[c],[d],[f]])

PX0 returns a 5x5 matrix
P also returns a 5x5 matrix

if I rewrite the original format provided for X0 so that:
X0 = np.array([[a, b, c, d, e]])

Then I a 1x5 matrix for X1 regardless if I multiply PX0 or X0P

What’s going on here?

I can’t quite grasp what you have written there in text.

It would help if you post a screen capture image that shows what part of the course or notebook you’re asking about.

Thanks I found a textbook that was able to point me in the right direction. I was using the wrong syntax for the multiplication (I was using * instead of @ ) — Can you please remind me what * does in an A*B operation of arrays?

I recommend you not use the @ operator. It hides what’s actually happening, and in this course you’re supposed to be learning the details.

With numpy and matrix operands, the * operator is the element-wise product. It doesn’t include any summations.

I think it’s better at this stage to use np.dot() or np.matmul() for vector matrix products, or np.multiply() for element-wise.

1 Like