Numpy.einsum for Julia?

I am wondering how to get functionality similar to numpy.einsum in Julia.

In particular, I have a 3rd order tensor, which I want to multiply by a 2nd tensor (matrix), compressing both dimensions to get a 1st order tensor (vector).

I am currently using PyCall so that I can use the numpy.einsum function as follows:

using PyCall @pyimport numpy as np a = rand(5,4,3) b = rand(5,4) c = np.einsum("ijk,ij", a,b) size(c) == (3,) 

It seems silly to rely on a python call to do tensor math. I also suggest that julia implementation will have speed advantages. However, I have no function for this in julia, and adding brute force is 1-2 orders of magnitude slower. What features can i use?

+2
source share
1 answer

Does sum(a.*b,(1,2)) not do what you want?

+3
source

All Articles