A Named Einsum.
NumPy's Einsum, but with named subscripts.
Neinsum is available on PyPI (and requires NumPy).
pip install neinsum
With neinsum
, it is possible to add names to the subscripts, i.e. instead of the indices-only ij
in np.einsum
, a named-subscript A_ij
has to be provided. The variable names - like A
(without indices) - are further used as keyword-arguments, see the example code-block. This is also supported for the output array.
import numpy as np
from neinsum import named_einsum
x = np.eye(3)
y = np.arange(9).reshape(3, 3)
named_einsum("A_ij,B_kl")(A=x, B=y)
# this is equal to
np.einsum("ij,kl", x, y)