[Numpy-discussion] Resize Method for Numpy Array

Christopher Barker Chris.Barker@noaa....
Thu Sep 24 12:24:45 CDT 2009

Alice Invernizzi wrote:

> 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()).

> Would you please be so kind to give some explanation for the existence 
> of resize operator for numpy array?

I don't find I use it that much, but it can be useful for the same 
reason that it is for lists, etc.

> If array size can be change, 
> what are the real advantages of using numpy array instead of list object?

This I can really answer! the "it's a known size" property of an 
nd-array is probably the least useful one I can think of. I think the 
pre-known size aspect of array objects is really an artifact of wanting 
efficient storage and processing, rather than a feature -- particularly 
in a dynamic language.

As for other advantages:

arrays are homogeneous data -- giving far more efficiency in a dynamic 

arrays are n-d -- you can slice and dice them as such -- it's easy to 
extract either a row or a column from a 2-d array, for instance.

slices of arrays are arrays with a view on the same data: this makes it 
easy to manipulate portions of an array with the same code you'd 
manipulate a full array.

array broadcasting

easy and efficient interchange of raw data with other data types, from 
C, C++ , Fortran, etc code.

and I could go on!

You might actually ask the question the other way -- if you can re-size 
an array -- why do you ever need to use a list?


Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception


More information about the NumPy-Discussion mailing list