How does the -1 in reshape command work?

When creating a post, please add:

how does the “-1” in this code snippet work?

X_flatten = X.reshape(X.shape[0], -1).T 

Please explain elaborately.

Yogesh S

This is a special syntax on reshape that you can find explained on the docpage for either numpy reshape or TF reshape, which Balaji has given us. It just says effectively “use whatever is left for this dimension”. You could explicitly calculate that value, but using -1 is simpler. Less code is better. :nerd_face:

1 Like