[Numpy-discussion] Zeroing an existing array

Todd Miller jmiller at stsci.edu
Wed May 14 13:27:04 EDT 2003


On Wed, 2003-05-14 at 16:21, Andrew P. Lentvorski, Jr. wrote:
> What is the official way to zero out an array in numarray/Numeric?
> 

I'm don't think there is one in numarray;  which is to say, I'd do what
you did below.

> While I can create a new array of all zeros and then assign it to the old 
> variable, this is extremely wasteful of memory.
> 
> Currently, I am just using:
> 
> >>> import numarray
> >>> a = numarray.arange(6)
> >>> a
> array([0, 1, 2, 3, 4, 5])
> >>> a[:] = 0.0
> >>> a
> array([0, 0, 0, 0, 0, 0])
> 
> I looked through the manual for a function or array mathod which would
> accomplish the same thing, but I didn't find an obvious one.  Did I miss
> something obvious?

I don't think so.

Todd





More information about the NumPy-Discussion mailing list