MCPcopy
hub / github.com/numpy/numpy / outer

Function outer

numpy/_core/numeric.py:905–989  ·  view source on GitHub ↗

Compute the outer product of two vectors. 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} ]] P

(a, b, out=None)

Source from the content-addressed store, hash-verified

903
904@array_function_dispatch(_outer_dispatcher)
905def outer(a, b, out=None):
906 """
907 Compute the outer product of two vectors.
908
909 Given two vectors `a` and `b` of length ``M`` and ``N``, respectively,
910 the outer product [1]_ is::
911
912 [[a_0*b_0 a_0*b_1 ... a_0*b_{N-1} ]
913 [a_1*b_0 .
914 [ ... .
915 [a_{M-1}*b_0 a_{M-1}*b_{N-1} ]]
916
917 Parameters
918 ----------
919 a : (M,) array_like
920 First input vector. Input is flattened if
921 not already 1-dimensional.
922 b : (N,) array_like
923 Second input vector. Input is flattened if
924 not already 1-dimensional.
925 out : (M, N) ndarray, optional
926 A location where the result is stored
927
928 Returns
929 -------
930 out : (M, N) ndarray
931 ``out[i, j] = a[i] * b[j]``
932
933 See also
934 --------
935 inner
936 einsum : ``einsum('i,j->ij', a.ravel(), b.ravel())`` is the equivalent.
937 ufunc.outer : A generalization to dimensions other than 1D and other
938 operations. ``np.multiply.outer(a.ravel(), b.ravel())``
939 is the equivalent.
940 linalg.outer : An Array API compatible variation of ``np.outer``,
941 which accepts 1-dimensional inputs only.
942 tensordot : ``np.tensordot(a.ravel(), b.ravel(), axes=((), ()))``
943 is the equivalent.
944
945 References
946 ----------
947 .. [1] G. H. Golub and C. F. Van Loan, *Matrix Computations*, 3rd
948 ed., Baltimore, MD, Johns Hopkins University Press, 1996,
949 pg. 8.
950
951 Examples
952 --------
953 Make a (*very* coarse) grid for computing a Mandelbrot set:
954
955 >>> import numpy as np
956 >>> rl = np.outer(np.ones((5,)), np.linspace(-2, 2, 5))
957 >>> rl
958 array([[-2., -1., 0., 1., 2.],
959 [-2., -1., 0., 1., 2.],
960 [-2., -1., 0., 1., 2.],
961 [-2., -1., 0., 1., 2.],
962 [-2., -1., 0., 1., 2.]])

Callers

nothing calls this directly

Calls 3

asarrayFunction · 0.70
multiplyFunction · 0.70
ravelMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…