From: Bill B. <wb...@gm...> - 2006-05-18 12:39:34
|
In Einstein summation notation, what numpy.dot() does now is: c_riqk =3D a_rij * b_qjk And you want: c_[r]ik =3D a_[r]ij * b_[r]jk where the brackets indicate a 'no summation' index. Writing the ESN makes it clearer to me anyway. :-) --bb On 5/18/06, Pau Gargallo <pau...@gm...> wrote: > > > I'm afraid I really don't understand the operation that you want. > > I think that the operation Angus wants is the following (at least I > would like that one ;-) > > if you have two 2darrays of shapes: > a.shape =3D (n,k) > b.shape =3D (k,m) > you get: > dot( a,b ).shape =3D=3D (n,m) > > Now, if you have higher dimensional arrays (kind of "arrays of matrices"= ) > a.shape =3D I+(n,k) > b.shape =3D J+(k,m) > where I and J are tuples, you get > dot( a,b ).shape =3D=3D I+J+(n,m) > dot( a,b )[ i,j ] =3D=3D dot( a[i],b[j] ) #i,j represent tup= les > That is the current behaviour, it computes the matrix product between > every possible pair. > For me that is similar to 'outer' but with matrix product. > > But sometimes it would be useful (at least for me) to have: > a.shape =3D I+(n,k) > b.shape =3D I+(k,m) > and to get only: > dot2( a,b ).shape =3D=3D I+(n,m) > dot2( a,b )[i] =3D=3D dot2( a[i], b[i] ) > > This would be a natural extension of the scalar product (a*b)[i] =3D=3D > a[i]*b[i] > If dot2 was a kind of ufunc, this will be the expected behaviour, > while the current dot's behaviour will be obtained by dot2.outer(a,b). > > Does this make any sense? > > Cheers, > pau > > |