10000 Merge pull request #5322 from yw5aj/tensordot_doc · pitrou/numpy@8993a5d · GitHub
[go: up one dir, main page]

Skip to content

Commit 8993a5d

Browse files
committed
Merge pull request numpy#5322 from yw5aj/tensordot_doc
Imrpoved docstring for np.tensordot()
2 parents 0afa5fc + af1cf19 commit 8993a5d

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

numpy/core/numeric.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,19 +1150,29 @@ def tensordot(a, b, axes=2):
11501150
----------
11511151
a, b : array_like, len(shape) >= 1
11521152
Tensors to "dot".
1153-
axes : variable type
1154-
* integer_like scalar
1155-
Number of axes to sum over (applies to both arrays); or
1156-
* (2,) array_like, both elements array_like of the same length
1157-
List of axes to be summed over, first sequence applying to `a`,
1158-
second to `b`.
1153+
axes : {integer_like, array_like}
1154+
* integer_like
1155+
If an int N, sum over the last N axes of `a` and the first N axes
1156+
of `b` in order. The sizes of the corresponding axes must match.
1157+
* (2,) array_like
1158+
Or, a list of axes to be summed over, first sequence applying to `a`,
1159+
second to `b`. Both elements array_like must be of the same length.
11591160
11601161
See Also
11611162
--------
11621163
dot, einsum< 8000 /span>
11631164
11641165
Notes
11651166
-----
1167+
Three common use cases are:
1168+
``axes = 0`` : tensor product $a\otimes b$
1169+
``axes = 1`` : tensor dot product $a\cdot b$
1170+
``axes = 2`` : (default) tensor double contraction $a:b$
1171+
1172+
When `axes` is integer_like, the sequence for evaluation will be: first
1173+
the -Nth axis in `a` and 0th axis in `b`, and the -1th axis in `a` and
1174+
Nth axis in `b` last.
1175+
11661176
When there is more than one axis to sum over - and they are not the last
11671177
(first) axes of `a` (`b`) - the argument `axes` should consist of
11681178
two sequences of the same length, with the first axis to sum over given
@@ -1211,7 +1221,7 @@ def tensordot(a, b, axes=2):
12111221
array([[a, b],
12121222
[c, d]], dtype=object)
12131223
1214-
>>> np.tensordot(a, A) # third argument default is 2
1224+
>>> np.tensordot(a, A) # third argument default is 2 for double-contraction
12151225
array([abbcccdddd, aaaaabbbbbbcccccccdddddddd], dtype=object)
12161226
12171227
>>> np.tensordot(a, A, 1)
@@ -1220,7 +1230,7 @@ def tensordot(a, b, axes=2):
12201230
[[aaaaacccccc, bbbbbdddddd],
12211231
[aaaaaaacccccccc, bbbbbbbdddddddd]]], dtype=object)
12221232
1223-
>>> np.tensordot(a, A, 0) # "Left for reader" (result too long to incl.)
1233+
>>> np.tensordot(a, A, 0) # tensor product (result too long to incl.)
12241234
array([[[[[a, b],
12251235
[c, d]],
12261236
...

0 commit comments

Comments
 (0)
0