Tensordot

Shipping
tensor_tensordot

General axis contraction (numpy tensordot) over matched axis lists; unit = product of operand units

Signature

Inputs

  • aSignal|ArrayrequiredFirst tensor operand.
  • bSignal|ArrayrequiredSecond tensor operand — contracted axes must match A's in size.

Outputs

  • resultSignal|ArrayThe contracted tensor; free axes of A precede free axes of B.

Parameters

KeyTypeDefaultNotes
axes_atext-1Comma-separated axes of A to contract (negative counts from the end), e.g. "1,2".
axes_btext0Comma-separated axes of B to contract — same length as A Axes, with matching sizes.

Description

Tensordot is the general-purpose axis contraction of numpy's tensordot. It sums products of a and b over the paired axis lists axes_a × axes_b, generalizing the dot product, matrix multiply, and higher-order contractions into one node.

The two axis lists are comma-separated, must be equal length, and the corresponding axis sizes must match. Each entry may be negative to count from the end. With the defaults axes_a = "-1", axes_b = "0", it contracts A's last axis against B's first — i.e. ordinary matrix-style multiplication. Supplying multi-axis lists like axes_a = "1,2", axes_b = "0,1" contracts several axes at once, which is common when reducing physics tensors or collapsing feature dimensions.

The output shape is A's remaining (free) axes followed by B's remaining axes. Because a contraction sums products, the result unit is the product of the operand units. Tensordot is stateless.

Mathematics

Examples

Default axes reproduce matmul

Leave axes_a = -1, axes_b = 0. Feeding a matrix and a matrix contracts A's last axis (size 3) against B's first (size 3), giving a result — exactly the matrix product.

Double contraction

For two rank-3 tensors A of shape and B of shape , set axes_a = 1,2 and axes_b = 0,1. Axes of size 3 and 5 are summed away, leaving a result — a two-axis contraction in a single node.

Applications

  • Collapsing multiple shared indices between physics or engineering tensors (stress-strain, moment-of-inertia contractions).
  • Reducing feature/channel axes in multi-dimensional data pipelines without reshaping to 2-D first.
  • Expressing inner products, matrix products, and higher-order sums with one configurable node.
  • Contracting a batched operator against a batched state when the contracted axes are not the trailing ones.

Neat

The single-axis default (`-1` against `0`) makes Tensordot a drop-in matrix multiply, so users can start with matmul semantics and generalize by editing two text fields.

Negative axis indices count from the end, matching numpy, so contractions stay valid even when ranks differ across the graph.

It enforces equal-length axis lists with matching sizes up front, turning shape mistakes into clear errors instead of silent miscontractions.

Known issues

The two axis lists must have equal length and matching axis sizes; a mismatch raises a backend error rather than broadcasting.

Axis order in the lists is significant — pairing is positional, so `axes_a = "1,2"` with `axes_b = "1,0"` contracts different axis pairs than `"0,1"`.

See also

tensordotcontractiontensornumpylinear-algebrastateless