[Numpy-discussion] Tensor-like product with extra indices?

Huaiyu Zhu huaiyu_zhu at yahoo.com
Sat Sep 14 00:25:02 EDT 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]

Aagh!  :-)

> 
> > 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

-- 
Huaiyu Zhu <huaiyu_zhu at yahoo.com>





More information about the NumPy-Discussion mailing list