[Numpy-discussion] resize in old Numeric

Timothy Hochberg tim.hochberg at ieee.org
Wed Dec 12 14:21:56 EST 2007


On Dec 12, 2007 11:39 AM, Christian Meesters <meesters at uni-mainz.de> wrote:

> Hi,
>
> For compatibility reasons (work with Biopython) I would like to use to
> Numeric in some code of mine. (Of course, I could make a little detour
> converting into numpy.array, but first I wonder whether somebody might
> know a solution for the problem with Numeric.)
>
> 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:


The first thing that I would try is switching from resize to reshape. In
general, you shouldn't be using resize except for certain odd applications
as it can potentially result in reallocating the data. I'm pretty sure what
you want is reshape.




>
>
> 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)
>
> /home/cm/Documents/projects/SAXS/Eury/MC_rigid/<ipython console> in
> <module>()
>
> <type 'exceptions.ValueError'>: cannot resize an array that has been
> referenced or is referencing
>  another array in this way.  Use the resize function.
>
> 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.
>
> Any ideas, what's going on or how to solve this?
> Numeric version is: 24.2
>
> TIA
> Christian
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>



-- 
.  __
.   |-\
.
.  tim.hochberg at ieee.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20071212/c109afac/attachment.html>


More information about the NumPy-Discussion mailing list