[Numpy-discussion] ndarray.resize method and reference counting
Scott Sinclair
scott.sinclair.za@gmail....
Tue Jan 13 05:48:08 CST 2009
Hi,
I'm confused by the following:
>>> import numpy as np
>>> np.__version__
'1.3.0.dev6116'
# I expect this
>>> x = np.eye(3)
>>> x.resize((5,5))
>>> x = np.eye(3)
>>> y = x
>>> x.resize((5,5))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: cannot resize an array that has been referenced or is referencing
another array in this way. Use the resize function
# I don't expect this
>>> x = np.eye(3)
>>> x
array([[ 1., 0., 0.],
[ 0., 1., 0.],
[ 0., 0., 1.]])
>>> x.resize((5,5), refcheck=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: cannot resize an array that has been referenced or is referencing
another array in this way. Use the resize function
>>> x.resize((5,5), refcheck=False)
>>> x
array([[ 1., 0., 0., 0., 1.],
[ 0., 0., 0., 1., 0.],
[ 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0.]])
Is there a reference counting bug, or am I misunderstanding something
about how Python works when I type a variable's name at the prompt?
Cheers,
Scott
More information about the Numpy-discussion
mailing list