bundles / numpy latest / numpy / ma / core / outer
function
numpy.ma.core:outer
source: build-install/usr/lib/python3.14/site-packages/numpy/ma/core.py :8261
Signature
def outer ( a , b ) Summary
Compute the outer product of two vectors.
Extended Summary
Given two vectors a and b of length M and N, respectively, the outer product [1] is
[[a_0*b_0 a_0*b_1 ... a_0*b_{N-1} ] [a_1*b_0 . [ ... . [a_{M-1}*b_0 a_{M-1}*b_{N-1} ]]
Parameters
a: (M,) array_likeFirst input vector. Input is flattened if not already 1-dimensional.
b: (N,) array_likeSecond input vector. Input is flattened if not already 1-dimensional.
out: (M, N) ndarray, optionalA location where the result is stored
Returns
out: (M, N) ndarrayout[i, j] = a[i] * b[j]
Notes
Masked values are replaced by 0.
Examples
Make a (*very* coarse) grid for computing a Mandelbrot set:import numpy as np rl = np.outer(np.ones((5,)), np.linspace(-2, 2, 5)) rl im = np.outer(1j*np.linspace(2, -2, 5), np.ones((5,))) im grid = rl + im gridAn example using a "vector" of letters:
x = np.array(['a', 'b', 'c'], dtype=object) np.outer(x, [1, 2, 3])
See also
- einsum
einsum('i,j->ij', a.ravel(), b.ravel())is the equivalent.- inner
- linalg.outer
An Array API compatible variation of
np.outer, which accepts 1-dimensional inputs only.- 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.
Aliases
-
numpy.ma.outer