Week 2: Global variable assertion error

1.AssertionError: Not all tests were passed for basic_sigmoid. Check your equations and avoid using global variables inside the function.
2.AssertionError: Not all tests were passed for softmax. Check your equations and avoid using global variables inside the function.

couldn’t identify where is my error, please assist.

Make sure you have followed the formula correctly:

Screen Shot 2021-10-27 at 12.47.03

2 Likes

I am getting the same error message; I can’t understand why. As suggested, to the extent that I can determine the formula is also correct.

Guidance will be appreciated.

Hi Hooman Hamidi,

Welcome to the community.

Kindly share the trace log and error you are getting, then only the mentors can help you out.

Thanks.

Thank you, this solved the issue for me :smiley:
For others, please don’t forget the negative sign before the x!

Reshape the training and test examples
#(≈ 2 lines of code)

train_set_x_flatten = …
test_set_x_flatten = …
YOUR CODE STARTS HERE
train_set_x_flatten = train_set_x_orig.reshape(train_set_x_orig.shape[1]*train_set_x_orig.shape[2]*train_set_x_orig.shape[3],train_set_x_orig.shape[0])
test_set_x_flatten = test_set_x_orig.reshape(test_set_x_orig.shape[1]*test_set_x_orig.shape[2]*test_set_x_orig.shape[3],test_set_x_orig.shape[0])

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))

got this error
AssertionError Traceback (most recent call last)
in
7 test_set_x_flatten = test_set_x_orig.reshape(test_set_x_orig.shape[1]*test_set_x_orig.shape[2]*test_set_x_orig.shape[3],test_set_x_orig.shape[0]).T
8 # Check that the first 10 pixels of the second image are in the correct place
----> 9 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.”
10 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.”
11

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

can anyone help

Hello @Daniyal_Adeeb,

The error message says “Wrong solution. Use (X.shape[0], -1).T.”.

Your approach and the approach in the error message will give the same shape, however, they do not give the same resulting arrays, so we cannot use the two approaches interchangably.

The train_set_x_orig uses the zeroth axis for different samples, however, in train_set_x_flatten, we are required to use the last (not the zeroth) axis for different samples, and this is why we cannot get rid of using transpose.

To see the difference, I suggest you to initialize a simple array of shape (3, 2, 2) , and then try both approaches to convert the array into another array of shape (2 * 2, 3). You want to pick the approach that in the resulting array_flatten[:, 0] contains data from the zeroth sample.

simple_array = np.array([ ... ])
array_flatten_1 = .... # approach 1
array_flatten_2 = .... # approach 2

print(simple_array [0]) # for data in the zeroth sample

print(array_flatten_1 [:, 0]) # check if approach 1 gives you back the zeroth sample
print(array_flatten_2 [:, 0]) # check if approach 2 gives you back the zeroth sample

After you convince yourself that you should use the approach suggested in the error message, please change your code accordingly.

Cheers,
Raymond

1 Like