[Numpy-discussion] A fix of the tensormultiply function in numarraycore.py

Nadav Horesh nadavh at visionsense.com
Mon Mar 22 05:24:14 CST 2004


The function did not work. Here is the correction:


def tensormultiply(array1, array2):
    """tensormultiply returns the product for any rank >=1 arrays, defined as:

    r_{xxx, yyy} = \sum_k array1_{xxx, k} array2_{k, yyyy}

    where xxx, yyy denote the rest of the a and b dimensions.
    """
    if array1.shape[-1] != array2.shape[0]:
        raise ValueError, "Unmatched dimensions"
    shape = array1.shape[:-1] + array2.shape[1:]
        return _gen.reshape(dot(_gen.reshape(array1, (-1, array1.shape[-1])),
                       _gen.reshape(array2, (array2.shape[0], -1))), shape)

  Nadav




More information about the Numpy-discussion mailing list