Is this a known error in Ipython with numpy?
![](https://secure.gravatar.com/avatar/d253a69e982f2c933f498541fd4748e0.jpg?s=120&d=mm&r=g)
Hello, I haven't worked hard yet to create a minimal runnable (reproduce-able) example but I wanted to check if this sounds familiar to anyone. I have a pretty involved program that resizes arrays in place with arr.resize. When I run it with python it completes and gives the expected result. When I run it in Ipython, I get the following error: ``` ---> 43 self._buffer.resize((count,)+self._dim) 44 45 ValueError: cannot resize an array that references or is referenced by another array in this way. Use the resize function ``` It was consistently doing this on the same array, after resizing two others before hand, even after rebooting. But trying to track it down it goes away even if I undo everything I did to try and track it down. Does this sound familiar?
![](https://secure.gravatar.com/avatar/fc2baa22f0b0e9fc8dc93733cb94103c.jpg?s=120&d=mm&r=g)
On Wed, Apr 27, 2016 at 7:48 PM, Elliot Hallmark <Permafacture@gmail.com> wrote:
Hello,
I haven't worked hard yet to create a minimal runnable (reproduce-able) example but I wanted to check if this sounds familiar to anyone.
I have a pretty involved program that resizes arrays in place with arr.resize. When I run it with python it completes and gives the expected result. When I run it in Ipython, I get the following error:
``` ---> 43 self._buffer.resize((count,)+self._dim) 44 45
ValueError: cannot resize an array that references or is referenced by another array in this way. Use the resize function ```
It was consistently doing this on the same array, after resizing two others before hand, even after rebooting. But trying to track it down it goes away even if I undo everything I did to try and track it down.
Does this sound familiar?
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion
I'd guess the issue is that your environment (IPython or IDLE or whatever) is keeping a reference to your array, for example so that you can refer to earlier outputs using the underscore _. Here's how I was able to reproduce the problem: This is OK:
import numpy as np a = np.arange(10) a.resize(3) a array([0, 1, 2])
This gives an error:
import numpy as np a = np.arange(10) a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) a.resize(3) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: cannot resize an array that references or is referenced by another array in this way. Use the resize function
Cheers, Alex
![](https://secure.gravatar.com/avatar/7857f26c1ef2e9bdbfa843f9087710f7.jpg?s=120&d=mm&r=g)
On Wed, Apr 27, 2016 at 8:49 PM, Alexander Griffing <argriffi@ncsu.edu> wrote:
On Wed, Apr 27, 2016 at 7:48 PM, Elliot Hallmark <Permafacture@gmail.com> wrote:
Hello,
I haven't worked hard yet to create a minimal runnable (reproduce-able) example but I wanted to check if this sounds familiar to anyone.
I have a pretty involved program that resizes arrays in place with arr.resize. When I run it with python it completes and gives the expected result. When I run it in Ipython, I get the following error:
``` ---> 43 self._buffer.resize((count,)+self._dim) 44 45
ValueError: cannot resize an array that references or is referenced by another array in this way. Use the resize function ```
It was consistently doing this on the same array, after resizing two others before hand, even after rebooting. But trying to track it down it goes away even if I undo everything I did to try and track it down.
You might find the %xdel magic to be useful: In [1]: %xdel? Docstring: Delete a variable, trying to clear it from anywhere that IPython's machinery has references to it. By default, this uses the identity of the named object in the user namespace to remove references held under other names. The object is also removed from the output history. Options -n : Delete the specified name from all namespaces, without checking their identity.
Does this sound familiar?
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion
I'd guess the issue is that your environment (IPython or IDLE or whatever) is keeping a reference to your array, for example so that you can refer to earlier outputs using the underscore _. Here's how I was able to reproduce the problem:
This is OK:
import numpy as np a = np.arange(10) a.resize(3) a array([0, 1, 2])
This gives an error:
import numpy as np a = np.arange(10) a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) a.resize(3) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: cannot resize an array that references or is referenced by another array in this way. Use the resize function
Cheers, Alex _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion
![](https://secure.gravatar.com/avatar/d253a69e982f2c933f498541fd4748e0.jpg?s=120&d=mm&r=g)
Hey Alex. Thanks. I was aware of that. However, I was simply doing `run myscript.py` on the first input line of the Ipython shell, so I did not expect this behaviour. The ipython list would be a better place to ask I guess, since the behaviour on numpy's part is to be expected. Just wondering if any numpy folks had seen this before. Elliot
participants (3)
-
Alexander Griffing
-
Elliot Hallmark
-
Nathan Goldbaum