W2_A1_Ex-1_NameError: name ‘train_set_x_orig’ 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.