Tensor contraction of a and b along specified axes.
Aliases:
tf.compat.v1.linalg.tensordottf.compat.v1.tensordottf.compat.v2.linalg.tensordottf.compat.v2.tensordottf.linalg.tensordot
tf.tensordot(
a,
b,
axes,
name=None
)
Tensordot (also known as tensor contraction) sums the product of elements from a and b over the indices specified by aaxes and baxes. The lists aaxes and baxes specify those pa``irs of axes along which to contract the tensors. The axis aaxes[i] of a must have the same dimension as axis baxes[i] of b for all i in range(0, len(aaxes)). The lists aaxes and b_axes must have identical length and consist of unique integers that specify valid axes for each of the tensors.
This operation corresponds to numpy.tensordot(a, b, axes).
Example 1: When a and b are matrices (order 2), the case axes = 1 is equivalent to matrix multiplication.
Example 2: When a and b are matrices (order 2), the case axes = [[1], [0]] is equivalent to matrix multiplication.
Example 3: Suppose that
and
represent two tensors of order 3. Then, contract(a, b, [[0], [2]]) is the order 4 tensor
whose entry corresponding to the indices
is given by:
.
In general, order(c) = order(a) + order(b) - 2*len(axes[0]).
Args:
a:Tensorof typefloat32orfloat64.b:Tensorwith the same typeasa.axes: EitherascalarN, oralist oranint32Tensorof shape [2, k]. Ifaxes isascalar, sum over the lastNaxes ofaand the firstNaxes ofbin order. Ifaxes isalist orTensorthe firstand second row contain the set of unique integers specifyingaxesalong which the contraction is computed, foraandb, respectively. The number ofaxes foraandbmustbe equal.name: Anamefor the operation (optional).
Returns:
A Tensor with the same type as a.
Raises:
ValueError: If the shapes ofa,b,andaxesare incompatible.IndexError: If the values inaxes exceed the rank of the corresponding tensor.