[Numpy-discussion] ufunc 's order of execution [relevant when output overlaps with input]

srean srean.list at gmail.com
Thu May 12 17:21:02 EDT 2011


  is there a guarantee that ufuncs will execute left to right and in
sequential order ? For instance is the following code standards compliant ?

>>> import numpy as n
>>> a=n.arange(0,5)
array([0, 1, 2, 3, 4])
>>> n.add(a[0:-1], a[1:], a[0:-1])
array([1, 3, 5, 7])

The idea was to reuse and hence save space. The place where I write to is
not accessed again.

I am quite surprised that the following works correctly.


I guess it uses a buffer and rebinds `a` to that buffer at the end. It is
also faster than

>>> n.add(a[0:-1], a[1:], a[1:])

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20110512/1147f1b7/attachment.html>

More information about the NumPy-Discussion mailing list