In-place array arithmetics

Expressions like 3*a-1 generates temporary arrays
With in-place modifications of arrays, we can avoid temporary arrays (to some extent)
b = a
b *= 3  # or multiply(b, 3, b)
b -= 1  # or subtract(b, 1, b)
Note: a is changed, use b = a.copy()
In-place operations:
a *= 3.0     # multiply a's elements by 3
a -= 1.0     # subtract 1 from each element
a /= 3.0     # divide each element by 3
a += 1.0     # add 1 to each element
a **= 2.0    # square all elements
Assign values to all elements of an existing array:
a[:] = 3*c - 1   # insert values into a
a = 3*c - 1      # let a refer to new array object

previousnexttable of contents