, 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 ]]

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.


out : ndarray, shaped (M, N)

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


Masked values are replaced by 0.


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

Next topic

This Page

Quick search