[Numpy-discussion] memory allocation at assignment
Thu Jun 28 13:42:33 CDT 2012
On Thu, Jun 28, 2012 at 7:04 PM, Chris Barker <firstname.lastname@example.org> 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 feels likes it happens inplace. Good to know it's not the case.
> well, c is being modified in place -- it's the a+b that is creating a new array.
> so if you have a c around for another purpose (other than to store the
> result of a+b -- it might make sense to use this approach. Though a
> little faster might be:
> c[:] = a
> c += b
That should be faster than c[:] = a + b, but still slower than
np.add(a, b, out=c).
More information about the NumPy-Discussion