ValueError resizing an ndarray

numpy, python, resize

Solution

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.

Problem

I have a small python script, and I always run into an error: ``` ValueError: cannot resize an array references or is referenced by another array in this way. Use the resize function ``` Code: ``` points = comp.findall('Points') # comp is a parsed .xml diffvals = np.arange(10, dtype=float) diffvals.resize(len(points),8) ``` But there are two things I do not understand: - I only get this error when I use debugger. - I have another script with identical code, and everything works fine. I checked this with debugger, all values, data types and so on are identical (except the memory addresses of course) I have no idea what I could possibly do to resolve this.

Original source