Re: [Numpy-discussion] memory allocation at assignment

2012-06-28 Thread srean
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

Re: [Numpy-discussion] memory allocation at assignment

2012-06-28 Thread Pierre Haessig
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

Re: [Numpy-discussion] memory allocation at assignment

2012-06-28 Thread Travis Oliphant
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.l...@gmail.com wrote: Yes it does. If you want to avoid this extra copy, and have a pre-existing

Re: [Numpy-discussion] memory allocation at assignment

2012-06-28 Thread Travis Oliphant
-- Travis Oliphant (on a mobile) 512-826-7480 On Jun 28, 2012, at 1:20 AM, Pierre Haessig pierre.haes...@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,

Re: [Numpy-discussion] memory allocation at assignment

2012-06-28 Thread astronomer
Hi Nathaniel, Thanks for the clearing my understand. This is exactly what i needed. Thanks, Nathaniel Smith wrote: On Thu, Jun 28, 2012 at 12:38 AM, astronomer shailendra.vi...@gmail.com wrote: Hi All, I am wondering if there any difference in memory overhead between the following

Re: [Numpy-discussion] memory allocation at assignment

2012-06-28 Thread Pierre Haessig
Hi, Le 28/06/2012 15:35, Travis Oliphant a écrit : 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. Thanks for the feedback about inplace assignment. On the other hand, just

Re: [Numpy-discussion] memory allocation at assignment

2012-06-28 Thread Chris Barker
On Thu, Jun 28, 2012 at 9:06 AM, Pierre Haessig On the other hand, just like srean mentionned, I think I also misused the c[:] = a+b syntax. I feel it's a bit confusing since this way of writing the assignment really feels likes it happens inplace. Good to know it's not the case. well, c is

Re: [Numpy-discussion] memory allocation at assignment

2012-06-28 Thread Nathaniel Smith
On Thu, Jun 28, 2012 at 7:04 PM, Chris Barker chris.bar...@noaa.gov wrote: On Thu, Jun 28, 2012 at 9:06 AM, Pierre Haessig On the other hand, just like srean mentionned, I think I also misused the c[:] = a+b syntax. I feel it's a bit confusing since this way of writing the assignment really

[Numpy-discussion] memory allocation at assignment

2012-06-27 Thread astronomer
Hi All, I am wondering if there any difference in memory overhead between the following code. a=numpy.arange(10) b=numpy.arange(10) c=a+b and a=numpy.arange(10) b=numpy.arange(10) c=numpy.empty_likes(a) c[:]=a+b Does the later code make a temproray array for the result of (a+b) and then copy

Re: [Numpy-discussion] memory allocation at assignment

2012-06-27 Thread Nathaniel Smith
On Thu, Jun 28, 2012 at 12:38 AM, astronomer shailendra.vi...@gmail.com wrote: Hi All, I am wondering if there any difference in memory overhead between the following code. a=numpy.arange(10) b=numpy.arange(10) c=a+b and a=numpy.arange(10) b=numpy.arange(10) c=numpy.empty_likes(a)