| View source on GitHub | 
Tensor contraction of a and b along specified axes and outer product.
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 axes.
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: When a and b are matrices (order 2), the case axes=0 gives the outer product, a tensor of order 4.
Example 4: Suppose that \(a_{ijk}\) and \(b_{lmn}\) represent two tensors of order 3. Then, contract(a, b, [[0], [2]]) is the order 4 tensor \(c_{jklm}\) whose entry corresponding to the indices \((j,k,l,m)\) is given by:
\( c_{jklm} = \sum_i a_{ijk} b_{lmi} \).
In general, order(c) = order(a) + order(b) - 2*len(axes[0]).
| Args | |
|---|---|
| a | Tensorof typefloat32orfloat64. | 
| b | Tensorwith the same type asa. | 
| axes | Either a scalar N, or a list or anint32Tensorof shape [2, k]. If axes is a scalar, sum over the last N axes of a and the first N axes of b in order. If axes is a list orTensorthe first and second row contain the set of unique integers specifying axes along which the contraction is computed, foraandb, respectively. The number of axes foraandbmust be equal. Ifaxes=0, computes the outer product betweenaandb. | 
| name | A name for the operation (optional). | 
| Returns | |
|---|---|
| A Tensorwith the same type asa. | 
| Raises | |
|---|---|
| ValueError | If the shapes of a,b, andaxesare incompatible. | 
| IndexError | If the values in axes exceed the rank of the corresponding tensor. | 
    © 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
    https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/tensordot