[Numpy-discussion] minor improvment to ones

Sturla Molden sturla at molden.no
Fri Jan 30 09:16:25 EST 2009


On 1/30/2009 3:07 PM, Grissiom wrote:

> Is fill function has any advantage over ones(size)*x ?

You avoid filling with ones, all the multiplications and creating an 
temporary array. It can be done like this:

a = empty(size)
a[:] = x

Which would be slightly faster and more memory efficient.


S.M.



More information about the NumPy-Discussion mailing list