O'Reilly logo
  • Mrinali Gupta thinks this is interesting:

Ufuncs accept an optional out argument that allows them to operate in-place on arrays

From

Cover of Python for Data Analysis, 2nd Edition

Note

In [151]: arr Out[151]: array([-3.2623, -6.0915, -6.663 , 5.3731, 3.6182, 3.45 , 5.0077])

In [152]: np.sqrt(arr) Out[152]: array([ nan, nan, nan, 2.318 , 1.9022, 1.8574, 2.2378])

In [153]: np.sqrt(arr, arr) Out[153]: array([ nan, nan, nan, 2.318 , 1.9022, 1.8574, 2.2378])

In [154]: arr Out[154]: array([ nan, nan, nan, 2.318 , 1.9022, 1.8574, 2.2378])