←back to thread

I don't like NumPy

(dynomight.net)
480 points MinimalAction | 1 comments | | HN request time: 0.203s | source
1. sundarurfriend ◴[] No.43998456[source]
> D = 1/(LM) np.einsum('klm,ln,km->kn', A, B, C)

The first time I came across Einsums was via the Tullio.jl package, and it seemed like magic to me. I believe the equivalent of this would be:

     @tullio D[k, n] = 1/(L*M) * A[k, l, m] * B[l, n] * C[k, m]
which is really close to the mathematical notation.

To my understanding, template strings from PEP 750 will allow for something like:

    D = 1/(L*M) * np.einsum(t'{A}[k,l,m] * {B}[l,n] * {C}[k,m]')
right? If so, that'd be pretty neat to have.