I am trying to understand the difference between numpy.resize and numpy.reshape. I know that resize will return a new array and that reshape will maintain the same underlying data and only adjust the size (I'm assuming it does this by changing the stride). However, for both functions I would expect to be able to use the -1 syntax to specify an axis size. However, this appears to only work for reshape. For example, trying to reshape/resize this 1-D array of shape (444,) to an array of shape (4, 111) gives two different results depending on whether you use resize or reshape:
import numpy as np
test = np.arange(0, 444)
print(test.shape)
print(np.resize(test, (4, -1)).shape)
print(np.reshape(test, (4, -1)).shape)
prints
(444,)
(4, 110)
(4, 111)
I'm assuming that I'm missing something about the resize function, but I would expect it to either output a shape that is compatible with (444,) or throw an error.
resizemethod on the array itself explicitly forbids negative dimensions, I wonder if this method should be doing the same thing.resizeisn't used often, and is best if you want to change the total number of elements. That is, it can clip or pad. Beware the function and method behave quite differently.reshapecan't change the total number of elements, and is widely used to change the total number of dimensions - to 2d, or 1d etc. I wouldn't treat them as alternatives.np.resizeexplain its use of -1?