Exemplo n.º 1
0
def tensordot(a, b, axes=2):
    '''Tensor dot product of two arrays
    '''
    if isinstance(axes, int):
        bx = range(axes)
        ao = a.rank - axes - 1
        ax = [ ao + i for i in bx ]
    else:
        t = type(axes)
        if t is _types.ListType or t is _types.TupleType:
            if len(t) == 0:
                raise ValueError, 'Given axes sequence should be non-empty'

            if len(t) == 1:
                ax = axes[0]
                bx = axes[0]
            else:
                ax = axes[0]
                bx = axes[1]

            ta = type(ax)
            tal = ta is _types.ListType or ta is _types.TupleType
            tb = type(bx)
            tbl = tb is _types.ListType or tb is _types.TupleType
            if tal != tbl:
                if tal:
                    bx = list(bx)
                else:
                    ax = list(ax)
        else:
            raise ValueError, 'Given axes has wrong type'

    return _linalg.tensorDotProduct(a, b, ax, bx)
Exemplo n.º 2
0
def inner(a, b):
    '''Inner product of two arrays (sum product over last dimensions)'''
    return _linalg.tensorDotProduct(a, b, -1, -1)
Exemplo n.º 3
0
def dot(a, b):
    '''Dot product of two arrays'''
    return _linalg.dotProduct(a, b)
Exemplo n.º 4
0
def vdot(a, b):
    '''Dot product of two vectors with first vector conjugated if complex'''
    return _linalg.dotProduct(conjugate(a.flatten()), b.flatten())
Exemplo n.º 5
0
def dot(a, b):
    """Dot product of two arrays"""
    return _linalg.dotProduct(a, b)