nlcpy.outer

nlcpy.outer(a, b, out=None)[ソース]

Computes an outer product of two vectors.

Given two vectors, a = [a0, a1, ..., aM] and b = [b0, b1, ..., bN], the outer produce is:

[[a0*b0 a0*b1 ... a0*bN]
[a1*b0   .            ]
[ ...         .       ]
[aM*b0           aM*bN]]
Parameters
a(M,) array_like

First input vector. Input is flattened if not already 1-dimensional.

b(N,) array_like

Second input vector. Input is flattened if not already 1-dimensional.

out(M, N) ndarray, optional

A location where the result is stored.

Returns
outndarray

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

参考

inner

Computes an inner product of two arrays.

ufunc.outer

Applies the ufunc op to all pairs (a, b) with a in A and b in B.

Examples

Make a (very coarse) grid for computing a Mandelbrot set:

>>> import nlcpy as vp
>>> rl = vp.outer(vp.ones((5,)), vp.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 = vp.outer(1j*vp.linspace(2, -2, 5), vp.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]])