-1

I am trying to solve the programming assessment: Logistic Regression with a Neural Network Mindset from the week2 of 'Neural network & deep learning course' by Andrew NG on coursera.

This is the code:

# X.reshape(X.shape[0], -1).T
train_set_x_flatten = train_set_x_orig.reshape(train_set_x_orig.shape[0], -1).T
print(train_set_x_flatten.shape)
print ("train_set_x_flatten shape: " + str(train_set_x_flatten.shape))
train_set_x_flattenExtra = train_set_x_orig.reshape(-1, train_set_x_orig.shape[0])
print ("train_set_x_flattenExtra shape: " + str(train_set_x_flattenExtra.shape))
print()

# X.reshape(-1, X.shape[0])
test_set_x_flatten = test_set_x_orig.reshape(test_set_x_orig.shape[0], -1).T
print((test_set_x_orig.reshape(-1, test_set_x_orig.shape[0])).shape)
print ("test_set_x_flatten shape: " + str(test_set_x_flatten.shape))
test_set_x_flattenExtra = test_set_x_orig.reshape(-1, test_set_x_orig.shape[0])
print(test_set_x_flattenExtra.shape)
print ("train_set_x_flattenExtra shape: " + str(train_set_x_flattenExtra.shape))
print()

As per my understanding, both should do the same thing and the output also shows the same shape, but coursera doesn't validate the X.reshape(-1, X.shape[0]) approach.

Are these two fn working different or its just coursera not validating another approach

Output: Output

  • Instead of only looking at the shapes, look at the actual _values_ in the arrays and see how they are arranged. – xdurch0 Jan 12 '22 at 11:05

1 Answers1

0

There's a subtle difference between

train_set_x_orig.reshape(-1,train_set_x_orig.shape[0]) and train_set_x_orig.reshape(train_set_x_orig.shape[0],-1).T

what train_set_x_orig.reshape(train_set_x_orig.shape[0],-1).T does is, it reshapes in such a way that the values are filled from 0th element and then to 1st element of the column,

On other hand the train_set_x_orig.reshape(-1,train_set_x_orig.shape[0]) starts from the 0th element of row and then to 1st element of the row Further: false_df vs actual_df

Ahmad Raza
  • 758
  • 7
  • 26