[Numpy-discussion] Initializing an array to a constant value

Pierre Haessig pierre.haessig at crans.org
Mon Feb 13 17:19:31 EST 2012


Le 13/02/2012 19:17, eat a écrit :
> wouldn't it be nice if you could just write:
> a= np.empty(shape).fill(A)
> this would be possible if .fill(.) just returned self.
Thanks for the tip. I noticed several times this was not working
(because of course, in the mean time, I forgot it...)
but I had totally overlooked the reasons (just imagining there was some
garbage collection magic vanishing my arrays !!)

I find the syntax "np.empty(shape).fill(A)" being indeed a good
alternative to the burden of creating a new numpy.fill (or numpy.filled
?) function.

-- 
Pierre
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20120213/8dc9041b/attachment.html>


More information about the NumPy-Discussion mailing list