[Numpy-discussion] memory allocation at assignment
Travis Oliphant
travis at continuum.io
Thu Jun 28 09:35:48 EDT 2012
--
Travis Oliphant
(on a mobile)
512-826-7480
On Jun 28, 2012, at 1:20 AM, Pierre Haessig <pierre.haessig at crans.org> wrote:
> Le 28/06/2012 02:34, Nathaniel Smith a écrit :
>>
>> 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)
> And is there a temporary copy when using inplace operators like:
>
> c = a.copy()
> c += b
>
> Is there a temporary (c+b) array which is then assigned to c, or is it really an inplace assignment as the operator += would suggest ?
>
It really is inplace. As Nathaniel mentioned --- all ufuncs take an out keyword.
The inplace mechanism uses this so that one input and the output are the same.
Travis
> Pierre
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list