Reshape array - Basic Python


C​an anyone help me explain this:

v = v.reshape(-1, 1)

To reshape an 3D image → 2D image which its dimension will be (image.shape[0]*image.shape[1], image.shape[2])

Can you give a general formula because I have seen this so far but not this case. using -1 in reshape but I don’t understand the principles like retain the last dimension ( by -1) how about 1 in (-1,1)?

The use of -1 in that syntax does not mean “the last index”. It means “use whatever dimensions are left over here”. So saying reshape(-1,1) just says that you want the result to be a column vector.


Thank you for your explaination

1 Like