[Numpy-discussion] memory allocation at assignment

Travis Oliphant travis at continuum.io
Thu Jun 28 09:28:58 EDT 2012


Yes,  the creation of the tmp *is* the creation of a new NumPy array.  So, it is as expensive.

Travis 

--
Travis Oliphant
(on a mobile)
512-826-7480


On Jun 28, 2012, at 12:44 AM, srean <srean.list at gmail.com> wrote:

>> 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.
> _______________________________________________
> 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