fn
einsum
→Tensoreinsum(equation: str, operands: Tensor = ())Evaluate an Einstein-summation expression over the given tensors.
Implements the general tensor contraction operator: each input is
indexed by labels declared in equation and the output retains
only the labels appearing on the right-hand side. Repeated labels
are summed; matching labels broadcast.
Parameters
equationstrEinsum equation of the form
"<lhs1>,<lhs2>,... -> <rhs>".*operandsTensor= ()Tensors corresponding to the comma-separated factors on the
left-hand side.
Returns
TensorTensor whose axes correspond to the labels on the right-hand
side of equation.
Notes
Matrix multiplication is the canonical example: "ij,jk->ik"
realises
More generally, einsum expresses traces ("ii->"), batched
contractions ("bij,bjk->bik"), and outer products
("i,j->ij") within one consistent notation.
Examples
>>> import lucid
>>> a = lucid.randn(2, 3)
>>> b = lucid.randn(3, 4)
>>> lucid.einops.einsum("ij,jk->ik", a, b).shape
(2, 4)