fn
tensordot
→Tensortensordot(a: Tensor, b: Tensor, dims: _int | list[list[_int]] = 2)Generalized tensor contraction over arbitrary axes.
Contracts a and b along the axes specified by dims, generalizing
matrix multiplication to higher-rank tensors. dims may be:
- an
intN— contract the lastNaxes ofawith the firstNaxes ofb; - a pair of axis lists
[[a_axes], [b_axes]]— contract the listed axes ofaagainst the listed axes ofbpairwise.
Parameters
aTensorFirst operand.
bTensorSecond operand.
dimsint or list of list of int= 2Specification of which axes to contract. Default is
2.Returns
TensorContracted result whose remaining axes are the un-contracted axes of a
followed by those of b.
Notes
Mathematical definition for axis lists :
where denotes the axes not contracted. Equivalent to a suitable
permutation followed by matmul and a reshape.
Examples
>>> import lucid
>>> a = lucid.zeros((3, 4, 5))
>>> b = lucid.zeros((4, 5, 2))
>>> lucid.tensordot(a, b, dims=2).shape
(3, 2)