The first step is to figure out why your *dw* values are the wrong shape. My guess is that you are using “elementwise” multiply instead of dot product in the formula for *dw*. Here’s the math formula that you need to write the code for:

dw = \displaystyle \frac {1}{m} X \cdot (A - Y)^T

The key point is that the operation between X and (A - Y)^T is a dot product style matrix multiply, not an “elementwise” multiply.

Look at the dimensions of the inputs to the first test case for *propagate*:

w is 2 x 1

X is 2 x 3

Y is 1 x 3

That means A will also be 1 x 3. So look at the dimensions on that dot product:

X is 2 x 3 and (A - Y)^T will be 3 x 1. So the result will be 2 x 1, which is the same as the shape of w. But if you use * instead of np.dot and leave out the transpose, then you will end up with a 2 x 3 output.

Here’s a thread about how to figure out when to use elementwise multiply and when to use dot product. Please have a look and see if that helps.