Broadcasting

Applies to: python

Broadcasting is NumPy's rule for combining arrays of different shapes without copying: smaller dimensions are stretched to match. It lets you, say, add a vector to every row of a matrix in one expression.

import numpy as np
M = np.ones((3, 4))
v = np.array([1, 2, 3, 4])
M + v          # v is added to each of the 3 rows

See also: numpy-array