numpy.outer

numpy.outer(a, b)

Returns the outer product of two vectors.

Given two vectors, [a0, a1, ..., aM] and [b0, b1, ..., bN], the outer product becomes:

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

a : array_like, shaped (M,)

First input vector. If either of the input vectors are not 1-dimensional, they are flattened.

b : array_like, shaped (N,)

Second input vector.

Returns:

out : ndarray, shaped (M, N)

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

Notes

The outer product of vectors is a special case of the Kronecker product.

Examples

>>> 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)

Previous topic

numpy.inner

Next topic

numpy.tensordot

This Page

Quick search