[Numpy-discussion] Resize Method for Numpy Array
"V. Armando Solé"
sole@esrf...
Thu Sep 24 10:38:14 CDT 2009
Alice Invernizzi wrote:
>
> Dear all,
>
> I have an Hamletic doubt concerning the numpy array data type.
> A general learned rule concerning the array usage in other high-level
> programming languages is that array data-type are homogeneous datasets
> of fixed dimension.
>
> Therefore, is not clear to me why in numpy the size of an array can be
> changed (either with the 'returning-value' resize() function either with
> the 'in-place' array method resize()).
> More in detail, if the existence of the first function
> ('returning-value') might make sense in array computing operation, the
> existence of the 'in-place' method really make no sense for me.
>
> Would you please be so kind to give some explanation for the existence
> of resize operator for numpy array? If array size can be change,
> what are the real advantages of using numpy array instead of list object?
> Thanks in avdance
Just to keep into the same line.
import numpy
a=numpy.arange(100.)
a.shape = 10, 10
b = a * 1 # just to get a copy
b.shape = 5, 2, 5, 5
b = (b.sum(axis=3)).sum(axis=1)
In that way, on b I have a binned image of a.
I would expect a.resize(5, 5) would have given something similar
(perhaps there is already something to make a binning). In fact
a.resize(5,5) is much closer to a crop than to a resize. I think the
resize name is misleading and should be called crop, but that is just my
view.
Armando
More information about the NumPy-Discussion
mailing list