flopscope.numpy.linalg.outer
fnp.linalg.outer(x1: 'ArrayLike', x2: 'ArrayLike', /) -> 'FlopscopeArray'[flopscope source][numpy source]
Compute the outer product of two vectors.
Adapted from NumPy docs np.linalg.outer
Cost
delegates to flops.outer
Flopscope Context
Delegates to `fnp.outer` which charges `m*n` FLOPs.
This function is Array API compatible. Compared to flops.outer it accepts 1-dimensional inputs only.
Parameters
- x1:(M,) array_like
One-dimensional input array of size
N. Must have a numeric data type.- x2:(N,) array_like
One-dimensional input array of size
M. Must have a numeric data type.
Returns
- out:(M, N) ndarray
out[i, j] = a[i] * b[j]
See also
Examples
Make a (very coarse) grid for computing a Mandelbrot set:
>>> rl = flops.linalg.outer(flops.ones((5,)), flops.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 = flops.linalg.outer(1j*flops.linspace(2, -2, 5), flops.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 = flops.array(['a', 'b', 'c'], dtype=object)
>>> flops.linalg.outer(x, [1, 2, 3])
array([['a', 'aa', 'aaa'],
['b', 'bb', 'bbb'],
['c', 'cc', 'ccc']], dtype=object)