tf.tensordot
Stay organized with collections
Save and categorize content based on your preferences.
Tensor contraction of a and b along specified axes.
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 a_axes
and b_axes
.
The lists a_axes
and b_axes
specify those pairs of axes along which to
contract the tensors. The axis a_axes[i]
of a
must have the same dimension
as axis b_axes[i]
of b
for all i
in range(0, len(a_axes))
. The lists
a_axes
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 \(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
|
Tensor of type float32 or float64 .
|
b
|
Tensor with the same type as a .
|
axes
|
Either a scalar N , or a list or an int32 Tensor of 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 or Tensor the first and second row contain
the set of unique integers specifying axes along which the contraction is
computed, for a and b , respectively. The number of axes for a and
b must be equal.
|
name
|
A name for the operation (optional).
|
Returns |
A Tensor with the same type as a .
|
Raises |
ValueError
|
If the shapes of a , b , and axes are incompatible.
|
IndexError
|
If the values in axes exceed the rank of the corresponding
tensor.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2020-10-01 UTC."],[],[],null,["# tf.tensordot\n\n|----------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/tensordot) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/ops/math_ops.py#L3921-L4087) |\n\nTensor contraction of a and b along specified axes.\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.linalg.tensordot`](/api_docs/python/tf/tensordot)\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.linalg.tensordot`](/api_docs/python/tf/tensordot), [`tf.compat.v1.tensordot`](/api_docs/python/tf/tensordot)\n\n\u003cbr /\u003e\n\n tf.tensordot(\n a, b, axes, name=None\n )\n\nTensordot (also known as tensor contraction) sums the product of elements\nfrom `a` and `b` over the indices specified by `a_axes` and `b_axes`.\nThe lists `a_axes` and `b_axes` specify those pairs of axes along which to\ncontract the tensors. The axis `a_axes[i]` of `a` must have the same dimension\nas axis `b_axes[i]` of `b` for all `i` in `range(0, len(a_axes))`. The lists\n`a_axes` and `b_axes` must have identical length and consist of unique\nintegers that specify valid axes for each of the tensors.\n\nThis operation corresponds to `numpy.tensordot(a, b, axes)`.\n\nExample 1: When `a` and `b` are matrices (order 2), the case `axes = 1`\nis equivalent to matrix multiplication.\n\nExample 2: When `a` and `b` are matrices (order 2), the case\n`axes = [[1], [0]]` is equivalent to matrix multiplication.\n\nExample 3: Suppose that \\\\(a_{ijk}\\\\) and \\\\(b_{lmn}\\\\) represent two\ntensors of order 3. Then, `contract(a, b, [[0], [2]])` is the order 4 tensor\n\\\\(c_{jklm}\\\\) whose entry\ncorresponding to the indices \\\\((j,k,l,m)\\\\) is given by:\n\n\\\\( c_{jklm} = \\\\sum_i a_{ijk} b_{lmi} \\\\).\n\nIn general, `order(c) = order(a) + order(b) - 2*len(axes[0])`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `a` | `Tensor` of type `float32` or `float64`. |\n| `b` | `Tensor` with the same type as `a`. |\n| `axes` | Either a scalar `N`, or a list or an `int32` `Tensor` of 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 or `Tensor` the first and second row contain the set of unique integers specifying axes along which the contraction is computed, for `a` and `b`, respectively. The number of axes for `a` and `b` must be equal. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor` with the same type as `a`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|--------------------------------------------------------------------|\n| `ValueError` | If the shapes of `a`, `b`, and `axes` are incompatible. |\n| `IndexError` | If the values in axes exceed the rank of the corresponding tensor. |\n\n\u003cbr /\u003e"]]