Broadcasting (or singleton expansion) applies a function element-wise across one or more multidimensional arrays, matching shapes of the arguments by repeating missing or singleton dimensions. Be sure to also tag the programming language; many languages with strong array support have implicit or explicit broadcasting behaviors, sometimes with idiosyncratic rules.
Many languages and frameworks have implementations of broadcasting (also known as singleton expansion), including but not limited to:
- julia Every function in Julia can be applied using broadcasting by simply transforming
f(x, y)
tof.(x, y)
. - matlab MATLAB's arithmetic operators implicitly expand singleton dimensions since R2016b. The higher-order
bsxfun
function can explicitly broadcast functions of binary operations over their arguments. - numpy Arithmetic and many functions implicitly broadcast in this python package. Arrays can be explicitly zipped together into a broadcasted shape with
numpy.broadcast
. - octave Octave behaves much like MATLAB.
- r R does not implement broadcasting, but its recycling behaviors can emulate broadcasting in some limited cases.
Some lower-level languages, like llvm (with getelementptr
) and cuda (with synchronizing warps) support broadcasting between scalars and vectors, but without support for higher dimensional arrays.