[Numpy-discussion] resize in old Numeric
Stefan van der Walt
stefan at sun.ac.za
Wed Dec 12 14:35:15 EST 2007
Hi Christiaan
On Wed, Dec 12, 2007 at 07:39:49PM +0100, Christian Meesters wrote:
> I need to flatten a simple 3x3 array and try to do that with resize.
> First time works, next time it doesn't. Here is an example:
>
> In [1]: from Numeric import *
>
> In [2]: a = array([[ 0.50622966, -0.54764389, -0.66619644],
> [ 0.44338279, -0.4973092, 0.7457228 ],[-0.73969131, -0.67288704,
> -0.00893311]])
>
> In [3]: a.resize((9,))
> Out[3]:
> array([ 0.50622966, -0.54764389, -0.66619644, 0.44338279, -0.4973092 ,
> 0.7457228 ,
> -0.73969131, -0.67288704, -0.00893311])
>
> In [4]: a.resize((9,))
> ---------------------------------------------------------------------------
> <type 'exceptions.ValueError'> Traceback (most recent call
> last)
You'll notice that this doesn't happen when you run those commands as
a script. IPython remembers the answer to the last command (as '_'
and in the output history), hence the reference that Numeric complains
about.
> Unfortunately, when applying resize on the actual array I have, I get a
> similar, yet slightly different error:
>
> Traceback (most recent call last):
> File "sym_get.py", line 37, in <module>
> s.inquire_relation()
> File "/usr/lib/python2.5/site-packages/mc_saxs/mc_rigid.py", line 915,
> in inquire_relation
> print rotation, rotation.resize((9,))
> ValueError: resize only works on contiguous arrays
>
> The arrays 'a' and 'rotation' are identical.
They may have identical values without having identical layout in
memory. Try a.ascontiguousarray().
Cheers
Stéfan
More information about the NumPy-Discussion
mailing list