[Numpy-discussion] zeros() default type in Numeric3

Stephen Walton stephen.walton at csun.edu
Mon Mar 28 15:40:17 EST 2005

Robert Kern wrote:

>   Float.new(shape, value=None) # empty
>   Float.new(shape, value=0)    # zeros
>   Float.new(shape, value=1)    # ones

Uhm, my first reaction to this kind of thing is "ugh," but maybe I'm 
just not thinking in the correct OO mode.  Is this any better than 
zeros() and ones()?  For that matter, is it any better than


Having said that, the main reason I use zeros() in MATLAB is to 
preallocate space.  MATLAB can dynamically grow arrays, so the following 
is legal:

do k=1:100

and produces a 100 by 100 array.  While legal, it is much faster to 
preallocate x by changing the first line to "x=zeros(100,100);".  Since 
NumPy arrays can't grow dynamically, perhaps this is a small issue.

More information about the NumPy-Discussion mailing list