[Numpy-discussion] ndarray: How to create and initialize with a value other than ones or zeros?

James Adams monocongo@gmail....
Thu Jun 6 14:56:06 CDT 2013


I would like to create an array object and initialize the array's
values with an arbitrary fill value, like you can do using the ones()
and zeros() creation routines to create and initialize arrays with
ones or zeros.  Is there an easy way to do this?  If this isn't
possible then what is the most efficient way to initialize a numpy
array with an arbitrary fill value?

In order to provide such an array creation routine I can imagine that
it'd be as simple as taking the code for ones() and/or zeros() and
modifying that code so that it provides an additional fill value
argument and then within the section which does the initialization of
the array it could use that fill value instead of 1 or 0.  Is this a
naive assumption?

Thanks in advance for your help with this issue.

--James


More information about the NumPy-Discussion mailing list