[Numpy-discussion] Array resize question closed
Cristi Constantin
darkgl0w@yahoo....
Wed Jun 17 02:07:41 CDT 2009
Thank you Neil Martinsen-Burrell and Scott Sinclair for your answers. :)
It's exactly what i wanted to know. I will use hstack and vstack to "resize" my array.
Have a nice day.
--- On Wed, 6/17/09, Scott Sinclair <scott.sinclair.za@gmail.com> wrote:
The resize method of ndarray is currently broken when the 'order'
keyword is specified, which is why you get the SystemError
http://projects.scipy.org/numpy/ticket/840
It's also worth knowing that the resize function and the ndarray
resize method both behave a little differently. Compare:
http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.resize.html
and
http://docs.scipy.org/doc/numpy/reference/generated/numpy.resize.html
Basically, the data in your original array is inserted into the new
array in the one dimensional order that it's stored in memory and any
remaining space is filled with repeats of the data (resize function)
or packed with zero's (resize array method).
# resize function
>>> import numpy as np
>>> a = np.array([[1, 2],[3, 4]])
>>> print a
[[1 2]
[3 4]]
>>> print np.resize(a, (3,3))
[[1, 2, 3],
[4, 1, 2],
[3, 4, 1]])
#resize array method
>>> b = np.array([[1, 2],[3, 4]])
>>> print b
[[1 2]
[3 4]]
>>> b.resize((3,3))
>>> print b
[[1 2 3]
[4 0 0]
[0 0 0]]
Neil's response gives you what you want in this case.
Cheers,
Scott
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090617/03277d43/attachment.html
More information about the Numpy-discussion
mailing list