ValueError Traceback (most recent call last)
in
----> 1 w3_unittest.test_forward_propagation(forward_propagation)
~/work/w3_unittest.py in test_forward_propagation(target_forward_propagation)
286
287 for test_case in test_cases:
→ 288 result = target_forward_propagation(test_case[“input”][“X”], test_case[“input”][“parameters”])
289
290 try:
in forward_propagation(X, parameters)
19 # Implement Forward Propagation to calculate Z.
20 ### START CODE HERE ### (~ 2 lines of code)
—> 21 Z = W*X + b
22 Y_hat = Z
23
ValueError: operands could not be broadcast together with shapes (1,2) (2,5)
The function is this
def forward_propagation(X, parameters):
“”"
Argument:
X – input data of size (n_x, m)
parameters – python dictionary containing your parameters (output of initialization function)
Returns:
Y_hat -- The output
"""
# Retrieve each parameter from the dictionary "parameters".
### START CODE HERE ### (~ 2 lines of code)
W = parameters["W"]
b = parameters["b"]
### END CODE HERE ###
# Implement Forward Propagation to calculate Z.
### START CODE HERE ### (~ 2 lines of code)
Z = W*X + b
Y_hat = Z
### END CODE HERE ###
assert(Y_hat.shape == (n_y, X.shape[1]))
return Y_hat
The * operator preforms element-wise multiplication of two matrices that have the same dimensions. In this case, the two matrices are not the same dimensions as you can see from the error message, they are of shapes (1,2) (2,5).
You can use a np.matmul() for a matrix multiplication, please see the reference menu.