[Numpy-discussion] memory allocation at assignment

srean srean.list at gmail.com
Thu Jun 28 01:44:36 EDT 2012


> Yes it does. If you want to avoid this extra copy, and have a
> pre-existing output array, you can do:
>
> np.add(a, b, out=c)
>
> ('+' on numpy array's is just a synonym for np.add; np.add is a ufunc,
> and all ufunc's accept this syntax:
>  http://docs.scipy.org/doc/numpy/reference/ufuncs.html
> )


Is the creation of the tmp as expensive as creation of a new numpy
array or is it somewhat  lighter weight (like being just a data
buffer). I sometimes use the c[:] syntax thinking I might benefit from
numpy.array re-use. But now I think that was misguided.



More information about the NumPy-Discussion mailing list