W2_A1_Ex-1_NameError: name ‘train_set_x_orig’ is not defined

I ran this cell and got the following result;

AssertionError Traceback (most recent call last)
in
10
11 # Check that the first 10 pixels of the second image are in the correct place
—> 12 assert np.alltrue(train_set_x_flatten[0:10, 1] == [196, 192, 190, 193, 186, 182, 188, 179, 174, 213]), “Wrong solution. Use (X.shape[0], -1).T.”
13 assert np.alltrue(test_set_x_flatten[0:10, 1] == [115, 110, 111, 137, 129, 129, 155, 146, 145, 159]), “Wrong solution. Use (X.shape[0], -1).T.”
14

AssertionError: Wrong solution. Use (X.shape[0], -1).T.

@rmwkwok, Please can you explain more what is wrong with it.
Thanks

I ran this cell and got the following result;

AssertionError Traceback (most recent call last)
in
10
11 # Check that the first 10 pixels of the second image are in the correct place
—> 12 assert np.alltrue(train_set_x_flatten[0:10, 1] == [196, 192, 190, 193, 186, 182, 188, 179, 174, 213]), “Wrong solution. Use (X.shape[0], -1).T.”
13 assert np.alltrue(test_set_x_flatten[0:10, 1] == [115, 110, 111, 137, 129, 129, 155, 146, 145, 159]), “Wrong solution. Use (X.shape[0], -1).T.”
14

AssertionError: Wrong solution. Use (X.shape[0], -1).T.

@paulinpaloalto Please throw more light on this.
Thanks

Here is a thread which explains why the flattening logic is written that way.

so why is it showing;

AssertionError: Wrong solution. Use (X.shape[0], -1).T.

please explain better

There must be something wrong with how you wrote the code. They showed you how to write it.

That other thread is the best explanation I can come up with for why the code needs to look the way that they showed.

Hi @paulinpaloalto, after debugging, here is what i got;

NameError Traceback (most recent call last)
in
10
11 # Check that the first 10 pixels of the second image are in the correct place
—> 12 assert np.alltrue((x.shape[0], -1).T == [196, 192, 190, 193, 186, 182, 188, 179, 174, 213]), “Wrong solution. Use (X.shape[0], -1).T.”
13 assert np.alltrue((x.shape[0], -1).T == [115, 110, 111, 137, 129, 129, 155, 146, 145, 159]), “Wrong solution. Use (X.shape[0], -1).T.”
14

NameError: name ‘x’ is not defined

please correct me once again.

thanks

Lower case vs upper case?

NameError Traceback (most recent call last)
in
10
11 # Check that the first 10 pixels of the second image are in the correct place
—> 12 assert np.alltrue((X.shape[0], -1).T == [196, 192, 190, 193, 186, 182, 188, 179, 174, 213]), “Wrong solution. Use (X.shape[0], -1).T.”
13 assert np.alltrue((X.shape[0], -1).T == [115, 110, 111, 137, 129, 129, 155, 146, 145, 159]), “Wrong solution. Use (X.shape[0], -1).T.”
14

NameError: name ‘X’ is not defined

I think you are taking a fundamentally incorrect approach here. It looks like you are modifying the test or “checking” code that is used to evaluate your code. Here’s what the “clean” version of that cell looks like in a fresh notebook:

# Reshape the training and test examples
#(≈ 2 lines of code)
# train_set_x_flatten = ...
# test_set_x_flatten = ...
# YOUR CODE STARTS HERE


# YOUR CODE ENDS HERE

# Check that the first 10 pixels of the second image are in the correct place
assert np.alltrue(train_set_x_flatten[0:10, 1] == [196, 192, 190, 193, 186, 182, 188, 179, 174, 213]), "Wrong solution. Use (X.shape[0], -1).T."
assert np.alltrue(test_set_x_flatten[0:10, 1] == [115, 110, 111, 137, 129, 129, 155, 146, 145, 159]), "Wrong solution. Use (X.shape[0], -1).T."

print ("train_set_x_flatten shape: " + str(train_set_x_flatten.shape))
print ("train_set_y shape: " + str(train_set_y.shape))
print ("test_set_x_flatten shape: " + str(test_set_x_flatten.shape))
print ("test_set_y shape: " + str(test_set_y.shape))

Notice that the assert statements reference train_set_x_flatten, not x or X. So why did you change that code? You should only need to fill in the code in the “YOUR CODE HERE” sections. If the tests fail, the solution is not to change the tests: it is to understand why your code fails the tests.

My suggestion would be to just rename your current notebook aside and get a fresh copy and start over. There are instructions for how to get a clean copy on the first topic on the DLS FAQ Thread.

If this your first exposure to any kind of computer programming, please realize that this course is not designed as an introduction to python programming: it assumes you are already a reasonably competent python programmer. If this is your first time programming, it might be a better plan to go take an “intro to python” course first and then come back here to learn Deep Learning.

I dont know Python programming though

But im not new in computer programming either.

This is the only cell giving me a little challenge. All other ones are understood by me, and the tests are all passed, except this.

The course requires you to know or learn python.

Just to close the loop on the public thread, I had a DM conversation with Chukwu and there was a simple error in the “flatten” logic that did not look like it was a problem of not understanding python syntax. One line was correct, but the other did not match.

Hi @rmwkwok. I ran this cell from my Second Programming test, Exercise 8, and got the following;

NameError Traceback (most recent call last)
in
----> 1 nn_model_test(nn_model)

~/work/release/W3A1/public_tests.py in nn_model_test(target)
261
262 t_X, t_Y = nn_model_test_case()
→ 263 parameters = target(t_X, t_Y, n_h, num_iterations=10000, print_cost=True)
264
265 print("W1 = " + str(parameters[“W1”]))

in nn_model(X, Y, n_h, num_iterations, print_cost)
46 A2, cache = forward_propagation(X,parameters)
47 cost = compute_cost(A2, Y)
—> 48 grads = backward_propagation(parameters, cache, X, Y)
49 parameters = update_parameters(parameters, grads)
50

NameError: name ‘backward_propagation’ is not defined

Where did i get it wrong please?

The problem is that you have accidentally converted the cell for backward_propagation from a code cell into a “markdown” or documentation cell, so that there is no function there. There is a way in the UI to convert a cell from code to markdown and markdown to code (Cell -> Cell Type), but if you can’t figure out how to do that, the other good strategy is just to get a clean copy of the notebook and “copy/paste” over your completed work. There is a topic about that on the DLS FAQ Thread.

Thanks a lot @paulinpaloalto