Compute tensor dot product along specified axes. Given two tensors, `a` and `b`, and an array_like object containing two array_like objects, ``(a_axes, b_axes)``, sum the products of `a`'s and `b`'s elements (components) over the axes specified by ``a_axes`` and ``b_axes``. The
(a, b, axes=2)
| 931 | |
| 932 | @array_function_dispatch(_tensordot_dispatcher) |
| 933 | def tensordot(a, b, axes=2): |
| 934 | """ |
| 935 | Compute tensor dot product along specified axes. |
| 936 | |
| 937 | Given two tensors, `a` and `b`, and an array_like object containing |
| 938 | two array_like objects, ``(a_axes, b_axes)``, sum the products of |
| 939 | `a`'s and `b`'s elements (components) over the axes specified by |
| 940 | ``a_axes`` and ``b_axes``. The third argument can be a single non-negative |
| 941 | integer_like scalar, ``N``; if it is such, then the last ``N`` dimensions |
| 942 | of `a` and the first ``N`` dimensions of `b` are summed over. |
| 943 | |
| 944 | Parameters |
| 945 | ---------- |
| 946 | a, b : array_like |
| 947 | Tensors to "dot". |
| 948 | |
| 949 | axes : int or (2,) array_like |
| 950 | * integer_like |
| 951 | If an int N, sum over the last N axes of `a` and the first N axes |
| 952 | of `b` in order. The sizes of the corresponding axes must match. |
| 953 | * (2,) array_like |
| 954 | Or, a list of axes to be summed over, first sequence applying to `a`, |
| 955 | second to `b`. Both elements array_like must be of the same length. |
| 956 | |
| 957 | Returns |
| 958 | ------- |
| 959 | output : ndarray |
| 960 | The tensor dot product of the input. |
| 961 | |
| 962 | See Also |
| 963 | -------- |
| 964 | dot, einsum |
| 965 | |
| 966 | Notes |
| 967 | ----- |
| 968 | Three common use cases are: |
| 969 | * ``axes = 0`` : tensor product :math:`a\\otimes b` |
| 970 | * ``axes = 1`` : tensor dot product :math:`a\\cdot b` |
| 971 | * ``axes = 2`` : (default) tensor double contraction :math:`a:b` |
| 972 | |
| 973 | When `axes` is integer_like, the sequence for evaluation will be: first |
| 974 | the -Nth axis in `a` and 0th axis in `b`, and the -1th axis in `a` and |
| 975 | Nth axis in `b` last. |
| 976 | |
| 977 | When there is more than one axis to sum over - and they are not the last |
| 978 | (first) axes of `a` (`b`) - the argument `axes` should consist of |
| 979 | two sequences of the same length, with the first axis to sum over given |
| 980 | first in both sequences, the second axis second, and so forth. |
| 981 | |
| 982 | The shape of the result consists of the non-contracted axes of the |
| 983 | first tensor, followed by the non-contracted axes of the second. |
| 984 | |
| 985 | Examples |
| 986 | -------- |
| 987 | A "traditional" example: |
| 988 | |
| 989 | >>> a = np.arange(60.).reshape(3,4,5) |
| 990 | >>> b = np.arange(24.).reshape(4,3,2) |