numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
outer(a, b, out=None)

Given two vectors, a = [a0, a1, ..., aM] and b = [b0, b1, ..., bN] , the outer product is:

[[a0*b0  a0*b1 ... a0*bN ]
 [a1*b0    .
 [ ...          .
 [aM*b0            aM*bN ]]

Parameters

a : (M,) array_like

First input vector. Input is flattened if not already 1-dimensional.

b : (N,) array_like

Second input vector. Input is flattened if not already 1-dimensional.

out : (M, N) ndarray, optional

A location where the result is stored

versionadded

Returns

out : (M, N) ndarray

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

Compute the outer product of two vectors.

See Also

einsum

einsum('i,j->ij', a.ravel(), b.ravel()) is the equivalent.

inner
tensordot

np.tensordot(a.ravel(), b.ravel(), axes=((), ())) is the equivalent.

ufunc.outer

A generalization to dimensions other than 1D and other operations. np.multiply.outer(a.ravel(), b.ravel()) is the equivalent.

Examples

Make a (very coarse) grid for computing a Mandelbrot set:

>>> rl = np.outer(np.ones((5,)), np.linspace(-2, 2, 5))
... rl array([[-2., -1., 0., 1., 2.], [-2., -1., 0., 1., 2.], [-2., -1., 0., 1., 2.], [-2., -1., 0., 1., 2.], [-2., -1., 0., 1., 2.]])
>>> im = np.outer(1j*np.linspace(2, -2, 5), np.ones((5,)))
... im array([[0.+2.j, 0.+2.j, 0.+2.j, 0.+2.j, 0.+2.j], [0.+1.j, 0.+1.j, 0.+1.j, 0.+1.j, 0.+1.j], [0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], [0.-1.j, 0.-1.j, 0.-1.j, 0.-1.j, 0.-1.j], [0.-2.j, 0.-2.j, 0.-2.j, 0.-2.j, 0.-2.j]])
>>> 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.outer(x, [1, 2, 3]) array([['a', 'aa', 'aaa'], ['b', 'bb', 'bbb'], ['c', 'cc', 'ccc']], dtype=object)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.linalg._decomp_svd.svdvals numpy.kron dask.array.einsumfuncs.einsum scipy.linalg._decomp_update.qr_update dask.array.ufunc.ufunc.outer scipy.signal._signaltools.fftconvolve numpy.cross scipy.spatial._geometric_slerp.geometric_slerp numpy.core._multiarray_umath.c_einsum dask.array.routines.outer numpy.einsum

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/core/numeric.py#851
type: <class 'function'>
Commit: