W2_A2_AssertionError: Wrong shape for d['w']. (2, 1) != (4, 1)

Good day

AssertionError Traceback (most recent call last)
in
1 from public_tests import *
2
----> 3 model_test(model)

~/work/release/W2A2/public_tests.py in model_test(target)
130
131 assert type(d[‘w’]) == np.ndarray, f"Wrong type for d[‘w’]. {type(d[‘w’])} != np.ndarray"
→ 132 assert d[‘w’].shape == (X.shape[0], 1), f"Wrong shape for d[‘w’]. {d[‘w’].shape} != {(X.shape[0], 1)}"
133 assert np.allclose(d[‘w’], expected_output[‘w’]), f"Wrong values for d[‘w’]. {d[‘w’]} != {expected_output[‘w’]}"
134

AssertionError: Wrong shape for d[‘w’]. (2, 1) != (4, 1)

Please tell me where to look for the error

That type of dimension mismatch typically means you have referenced global variables somewhere, instead of the local variables in the scope of the model function. E.g. passing the global variable dim as the argument to the initialize routine. But in that case, it usually results in an earlier failure the first time you call optimize and propagate. Here the error happens at the very end, so it probably means you have the wrong variable name for the dictionary containing the parameters that is returned by model. That’s the place to look for the global variable reference.

Good day.
My variable name for the dictionary containing the parameters that is returned by model:
w = params[“w”]
b = params[“b”]

Good day. I managed to fix all the errors. Thank you.

Glad to hear that you were able to finally solve it. In your case, it didn’t fail even in the predict calls after the call to optimize, so you must have had everything right up until the point at which you construct the overall return values.