[Numpy-discussion] Constant array
Charles R Harris
charlesr.harris at gmail.com
Mon Aug 28 02:05:27 EDT 2006
Hi Carlos,
On 8/27/06, Carlos Pita <carlosjosepita at yahoo.com.ar> wrote:
>
> Hi all!
> Is there a more efficient way of creating a constant K-valued array of
> size N than:
> zeros(N) + K
> ?
>
Maybe something like this:
In [12]: a = empty((3,3), dtype=int)
In [13]: a.fill(11)
In [14]: a
Out[14]:
array([[11, 11, 11],
[11, 11, 11],
[11, 11, 11]])
I haven't timed it, so don't know how fast it is. Looking at this makes me
think fill should return the array so that one could do something like: a =
empty((3,3), dtype=int).fill(10)
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060828/cd2af3fc/attachment-0001.html>
More information about the NumPy-Discussion
mailing list