Linear Algebra for ML wk3 assignment exercise 4

can someone please give a hint on what I’m supposed to do here?

``````# Retrieve each parameter from the dictionary "parameters".
### START CODE HERE ### (~ 2 lines of code)
W = None
b = None
### END CODE HERE ###
``````

the instruction is: 1. Retrieve each parameter from the dictionary “parameters” (which is the output of `initialize_parameters()`) by using `parameters[".."]`.

Thanks

2 Likes

I’m not a mentor for that course, but I suspect you’re supposed to use some construct like this:
`<variable_name> = parameters["key"].`

Since “parameters” is a dictionary, you can access each value using its key.

1 Like
``````Here's what you need to do ...
``````

{moderator edit: code removed}

1 Like

thanks for trying TMosh

1 Like

Generally posting code for the assignments is not allowed. That’s why I gave guidance instead of just providing the answer.

1 Like

thanks, ultron_code. That works and in the following step `print(Y_hat)` is giving the expected output.

However the `w3_unittest.test_forward_propagation(forward_propagation)` is failing as follows:

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)
26 print(f"m = {m}")
27
—> 28 Z = W * X + b
29 Y_hat = Z
30 ### END CODE HERE ###

ValueError: operands could not be broadcast together with shapes (1,2) (2,5)

my code is:

``````# Retrieve each parameter from the dictionary "parameters".
### START CODE HERE ### (~ 2 lines of code)
# moderator edit: code removed
### END CODE HERE ###

# Implement Forward Propagation to calculate Z.
### START CODE HERE ### (~ 2 lines of code)
print ('The shape of X: ' + str(X.shape))
print (f'The shape of W: {W.shape}')
print (f'The shape of b: {b.shape}\n')

#moderator edit: code removed

### END CODE HERE ###
``````

and the print output is:

The shape of X: (1, 30)
The shape of W: (1, 1)
The shape of b: (1, 1)

The shape of X: (1, 30)
The shape of W: (1, 1)
The shape of b: (1, 1)

The shape of X: (2, 5)
The shape of W: (1, 2)
The shape of b: (1, 1)

why do the shapes of `X` and `W` change? thanks

2 Likes

so I figured out my error was doing {moderator edit: code removed}. With this change the test cases in exercises 4 & 5 both passed.

however my print statements as shown in my previous reply still are showing that the shapes of `X` and `W` change from `(1,30)` and `(1,1)` to `(2,5)` and `(1,2)` somewhere along the line during the test cases despite all the expected output are generated. Why is that? thanks

4 Likes

@plaudev Thanks for posting this. I got the same error, and your guidance was absolutely helpful!

1 Like