[Numpy-discussion] Tensor-like product with extra indices?
huaiyu_zhu at yahoo.com
Sat Sep 14 00:25:02 CDT 2002
On 13 Sep 2002, Konrad Hinsen wrote:
> Untested, but the idea should work:
> def ravel_index(array, *indices):
> offsets = Numeric.multiply.accumulate(array.shape[1:][::-1])[::-1]
> return Numeric.sum(Numeric.array(indices[:-1])*offsets) + indices[-1]
> > 2. Suppose the above function is called ravel_index and its
> > inverse unravel_index.
> > Given a list of matrices [A0, A1, ...] is there a function that
> > calculates a matrix B such that
> > B[i,j] = A0[i0,j] * A1[i1,j] * ...
> > where i = ravel_index(i0, i1, ...).
> Not for all i, which I assume is what you want to do.
I end up using two for-loops, one over j and the other over [A0, ...].
Hoping the speed problem will not be too bad later on.
Huaiyu Zhu <huaiyu_zhu at yahoo.com>
More information about the Numpy-discussion