MCPcopy Index your code
hub / github.com/numpy/numpy / tensordot

Function tensordot

numpy/_core/numeric.py:997–1218  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

995
996@array_function_dispatch(_tensordot_dispatcher)
997def tensordot(a, b, axes=2):
998 """
999 Compute tensor dot product along specified axes.
1000
1001 Given two tensors, `a` and `b`, and an array_like object containing
1002 two array_like objects, ``(a_axes, b_axes)``, sum the products of
1003 `a`'s and `b`'s elements (components) over the axes specified by
1004 ``a_axes`` and ``b_axes``. The third argument can be a single non-negative
1005 integer_like scalar, ``N``; if it is such, then the last ``N`` dimensions
1006 of `a` and the first ``N`` dimensions of `b` are summed over.
1007
1008 Parameters
1009 ----------
1010 a, b : array_like
1011 Tensors to "dot".
1012
1013 axes : int or (2,) array_like
1014 * integer_like
1015 If an int N, sum over the last N axes of `a` and the first N axes
1016 of `b` in order. The sizes of the corresponding axes must match.
1017 * (2,) array_like
1018 Or, a list of axes to be summed over, first sequence applying to `a`,
1019 second to `b`. Both elements array_like must be of the same length.
1020 Each axis may appear at most once; repeated axes are not allowed.
1021 For example, ``axes=([1, 1], [0, 0])`` is invalid.
1022 Returns
1023 -------
1024 output : ndarray
1025 The tensor dot product of the input.
1026
1027 See Also
1028 --------
1029 dot, einsum
1030
1031 Notes
1032 -----
1033 Three common use cases are:
1034 * ``axes = 0`` : tensor product :math:`a\\otimes b`
1035 * ``axes = 1`` : tensor dot product :math:`a\\cdot b`
1036 * ``axes = 2`` : (default) tensor double contraction :math:`a:b`
1037
1038 When `axes` is integer_like, the sequence of axes for evaluation
1039 will be: from the -Nth axis to the -1th axis in `a`,
1040 and from the 0th axis to (N-1)th axis in `b`.
1041 For example, ``axes = 2`` is the equal to
1042 ``axes = [[-2, -1], [0, 1]]``.
1043 When N-1 is smaller than 0, or when -N is larger than -1,
1044 the element of `a` and `b` are defined as the `axes`.
1045
1046 When there is more than one axis to sum over - and they are not the last
1047 (first) axes of `a` (`b`) - the argument `axes` should consist of
1048 two sequences of the same length, with the first axis to sum over given
1049 first in both sequences, the second axis second, and so forth.
1050 The calculation can be referred to ``numpy.einsum``.
1051
1052 For example, if ``a.shape == (2, 3, 4)`` and ``b.shape == (3, 4, 5)``,
1053 then ``axes=([1, 2], [0, 1])`` sums over the ``(3, 4)`` dimensions of
1054 both arrays and produces an output of shape ``(2, 5)``.

Callers

nothing calls this directly

Calls 4

reshapeMethod · 0.80
asarrayFunction · 0.70
dotFunction · 0.70
prodMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…