Hi, I got the error message NameError: name ‘train_set_x’ is not defined. I tried again with the variable 'train_set_x_orig" but it returns the same name error. What should I do next?
Run all the above cells before running that particular cell.
Hi Saif, thanks for the prompt response. I did run the cells above.
And don’t change anything. Only write your code where it says
# WRITE YOUR CODE
Thanks, I re-ran the cells. Here’s the code I tried.
def flatten_dataset(X, num_px):
m = X.shape[0]
X_flatten = X.reshape(m, -1).T
return X_flatten / 255
num_px = train_set_x_orig.shape[1] # Assuming the images are square, i.e., num_px x num_px
train_set_x_flatten = flatten_dataset(train_set_x_orig, num_px)
test_set_x_flatten = flatten_dataset(test_set_x_orig, num_px)
print(“train_set_x_flatten shape:”, train_set_x_flatten.shape)
print(“test_set_x_flatten shape:”, test_set_x_flatten.shape)
The error message now - AssertionError: Wrong solution. Use (X.shape[0], -1).T.
Please share your full error (not code).
It seems like you are defining your own function flatten_dataset
. You are making things complex for you. It is not mentioned anywhere to define your own function.
Anyways. Don’t need to divide by 255 now. It will be down in a separate cell. Moreover, you can make num_px = -1
or just remove it from your function.
But I prefer not to define your own function but just write code separately for:
# train_set_x_flatten = ...
# test_set_x_flatten = ...
And one more point, make sure you write all your code where it is mentioned # YOUR CODE STARTS HERE
. Otherwise, grader will fail you.
Best,
Saif.