Generalised inner product

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Generalised inner product

pec27
Hi,

Does numpy have some sort of generalised inner product? For example I have arrays

a.shape = (5,6,7)
b.shape = (8,7,9,10)

and I want to perform a product over the 3rd axis of a and the 2nd of b, i.e.

c[i,j,k,l,m] = sum (over x) of a[i,j,x] * b[k,x,l,m]

I guess I could do it with swapaxes and numpy.dot or numpy.inner but I wondered if there was a general function.

Thanks,
Peter


_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Generalised inner product

Charles R Harris


On Mon, May 19, 2008 at 4:23 AM, Peter Creasey <[hidden email]> wrote:
Hi,

Does numpy have some sort of generalised inner product? For example I have arrays

a.shape = (5,6,7)
b.shape = (8,7,9,10)

and I want to perform a product over the 3rd axis of a and the 2nd of b, i.e.

c[i,j,k,l,m] = sum (over x) of a[i,j,x] * b[k,x,l,m]

I guess I could do it with swapaxes and numpy.dot or numpy.inner but I wondered if there was a general function.

Try tensordot.

Chuck



_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Generalised inner product

pec27
In reply to this post by pec27
> > c[i,j,k,l,m] = sum (over x) of a[i,j,x] * b[k,x,l,m]
> >
>
> Try tensordot.
>
> Chuck


That was exactly what I needed. Thanks!

Peter
_______________________________________________
Numpy-discussion mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/numpy-discussion