This is a pre-release version (latest).Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy latest / numpy / linalg / outer

_ArrayFunctionDispatcher

numpy.linalg:outer

source: build-install/usr/lib/python3.14/site-packages/numpy/linalg/_linalg.py:887

Signature

def outer(x1, x2, /)

Summary

Compute the outer product of two vectors.

Extended Summary

This function is Array API compatible. Compared to np.outer it accepts 1-dimensional inputs only.

Parameters

x1 : (M,) array_like

One-dimensional input array of size N. Must have a numeric data type.

x2 : (N,) array_like

One-dimensional input array of size M. Must have a numeric data type.

Returns

out : (M, N) ndarray

out[i, j] = a[i] * b[j]

Examples

Make a (*very* coarse) grid for computing a Mandelbrot set:
rl = np.linalg.outer(np.ones((5,)), np.linspace(-2, 2, 5))
rl
im = np.linalg.outer(1j*np.linspace(2, -2, 5), np.ones((5,)))
im
grid = rl + im
grid
✓
array([[-2.+2.j, -1.+2.j,  0.+2.j,  1.+2.j,  2.+2.j],
       [-2.+1.j, -1.+1.j,  0.+1.j,  1.+1.j,  2.+1.j],
       [-2.+0.j, -1.+0.j,  0.+0.j,  1.+0.j,  2.+0.j],
       [-2.-1.j, -1.-1.j,  0.-1.j,  1.-1.j,  2.-1.j],
       [-2.-2.j, -1.-2.j,  0.-2.j,  1.-2.j,  2.-2.j]])
An example using a "vector" of letters:
x = np.array(['a', 'b', 'c'], dtype=object)
np.linalg.outer(x, [1, 2, 3])
✓
array([['a', 'aa', 'aaa'],
       ['b', 'bb', 'bbb'],
       ['c', 'cc', 'ccc']], dtype=object)

See also

outer

Aliases

  • numpy.linalg.outer