numpy.ufunc.outer

ufunc.outer(A, B)

Compute the result of applying op to all pairs (a,b)

op.outer(A,B) is equivalent to op(A[:,:,...,:,newaxis,...,newaxis]*B[newaxis,...,newaxis,:,...,:]) where A has B.ndim new axes appended and B has A.ndim new axes prepended.

For A and B one-dimensional, this is equivalent to

r = empty(len(A),len(B))
for i in xrange(len(A)):
    for j in xrange(len(B)):
        r[i,j] = A[i]*B[j]

If A and B are higher-dimensional, the result has dimension A.ndim+B.ndim

Parameters:

A : array_like

First term

B : array_like

Second term

Returns:

r : ndarray

Output array

Examples

>>> np.multiply.outer([1,2,3],[4,5,6])
array([[ 4,  5,  6],
       [ 8, 10, 12],
       [12, 15, 18]])

Previous topic

numpy.ufunc.reduceat

Next topic

Routines

This Page

Quick search