문제

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

Specifically, I have a 3rd order tensor that I'm looking to multiply by a 2nd tensor (matrix), contracting both of the dimensions to yield a 1st order tensor (vector).

Currently, I'm using PyCall so that I can use the numpy.einsum function like so:

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 feels kind of silly to rely on calling python in order to do tensor math. I also imagine that a julia implementation would have speed advantages. However, I haven't any function for this in julia, and the brute force summation is 1-2 orders of magnitude slower. What functions can I use?

도움이 되었습니까?

해결책

Doesn't sum(a.*b,(1,2)) do what you want?

다른 팁

There is Tullio. Tullio is a pretty flexible einsum macro. It understands array operations written in index notation such as just permutations and matrix multiplication, but also convolutions, stencils, scatter/gather, and broadcasting.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top