ValueError resizing an ndarray ValueError resizing an ndarray numpy numpy

ValueError resizing an ndarray


You cannot resize NumPy arrays that share data with another array in-place using the resize method by default. Instead, you can create a new resized array using the np.resize function:

np.resize(a, new_shape)

or you can disable reference checking using:

a.resize(new_shape, refcheck=False)

The likely reason you are only seeing it with a debugger is that the debugger references the array to e.g. print it. Also, the debugger may not store references to temporary arrays before you assign them into a variable, which probably explains why the other script works.


Use

a = a.copy()

before resizing