[Matrix-SIG] Question for the NumPy gurus

Rob Hooft r.hooft@euromail.net
Thu, 5 Aug 1999 13:09:28 +0200 (MZT)


>>>>> "JS" == Janne Sinkkonen <janne@avocado.pc.helsinki.fi> writes:

 JS> dot() should really be extended for general tensor products,
 JS> i.e. to handle N-dimensional arrays with user-specified dimension
 JS> pairs over which inner products are computed:

 JS>    dot(A,B,((dimA1,dimB1),(dimA2,dimB2),...))

 JS> Then you could write

 JS>    dot(in1,in2,((-1,-1)))

I guess:

    dot(in1,in2,((-1,-1),))

This would definitely be a nice feature! I now have a routine:

def matvec(m,v):
    """Multiply a matrix with a vector, or any array of vectors"""
    v=Numeric.array(v,copy=0)
    ax=range(len(v.shape))[1:]+[0]
    return transpose(Numeric.innerproduct(m,v),axes=ax)

Which I use often with a 3x3-matrix and a 1340x1300 array of
3-vectors.  If/When the resulting transposed matrix needs to be made
contiguous, that copy actually takes longer than the matvec()
operation itself. OTOH, it doesn't make sense to optimize this, since
the progam that uses this spends even more time in
Numeric.arrayrange() :-(

Rob
-- 
=====   R.Hooft@EuroMail.net   http://www.xs4all.nl/~hooft/rob/  =====
=====   R&D, Nonius BV, Delft  http://www.nonius.nl/             =====
===== PGPid 0xFA19277D ========================== Use Linux! =========