summaryrefslogtreecommitdiff
path: root/numpy/core/numeric.py
diff options
context:
space:
mode:
authorStefan van der Walt <stefanv@berkeley.edu>2019-10-15 12:07:27 -0700
committerStefan van der Walt <stefanv@berkeley.edu>2019-10-15 12:07:27 -0700
commitd0731e118a5c40d866702f1b5da2be4d4f52ded9 (patch)
tree7ff1ce8d5cb4fe58056e3d02c99ff38610605ca8 /numpy/core/numeric.py
parent1e3c8d8a2b3c17462edf5928f1c29dd4b5d99128 (diff)
downloadnumpy-d0731e118a5c40d866702f1b5da2be4d4f52ded9.tar.gz
Add wording suggested by Eric. Remove extra example.
(The existing example already showcases the contracted axis stacking.)
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r--numpy/core/numeric.py39
1 files changed, 4 insertions, 35 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index 4d99ef256..52c796ade 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -1131,8 +1131,7 @@ def outer(a, b, out=None):
def tensordot(a, b, axes=2):
- """
- Compute tensor dot product along specified axes for arrays >= 1-D.
+ """Compute tensor dot product along specified axes for arrays >= 1-D.
Given two tensors (arrays of dimension greater than or equal to one),
`a` and `b`, and an array_like object containing two array_like
@@ -1175,42 +1174,12 @@ def tensordot(a, b, axes=2):
(first) axes of `a` (`b`) - the argument `axes` should consist of
two sequences of the same length, with the first axis to sum over given
first in both sequences, the second axis second, and so forth.
-
- It is worth noting that the axes of result could be reversed sometimes.
- And please refer to the example below:
+
+ The shape of the result consists of the non-contracted axes of the
+ first tensor, followed by the non-contracted axes of the second.
Examples
--------
- An axes shift test example:
- >>> diagMat=np.diag([1,1,1])
- >>> mat3D = np.array([[[ 0, 1, 2, 10],
- [ 3, 4, 5, 0],
- [ 6, 7, 8, 1]],
- [[ 9, 10, 11, 2],
- [12, 13, 14,3],
- [15, 16, 17,0]]])
- >>> newMat = np.tensordot(mat3D, diagMat, axes=([1],[1]))
- >>> print mat3D
- [[[ 0 1 2 10]
- [ 3 4 5 0]
- [ 6 7 8 1]]
- [[ 9 10 11 2]
- [12 13 14 3]
- [15 16 17 0]]]
- >>> print newMat
- [[[ 0 3 6]
- [ 1 4 7]
- [ 2 5 8]
- [10 0 1]]
- [[ 9 12 15]
- [10 13 16]
- [11 14 17]
- [ 2 3 0]]]
- >>> print newMat.shape
- (2, 4, 3)
- >>> print mat3D.shape
- (2, 3, 4)
-
A "traditional" example:
>>> a = np.arange(60.).reshape(3,4,5)