diff options
author | Matti Picus <matti.picus@gmail.com> | 2020-02-02 11:00:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-02 11:00:07 +0200 |
commit | 1d8d09b14ecf67cbea958ea5082fbbd422b1199e (patch) | |
tree | 0105ab5480432303a0c149d20f18816aef70533a /numpy/core/fromnumeric.py | |
parent | 330435bb3420d798de08f86bf47287e55cf9e516 (diff) | |
parent | 38064c32b6c258d4d13660ca81cbaeb7105af901 (diff) | |
download | numpy-1d8d09b14ecf67cbea958ea5082fbbd422b1199e.tar.gz |
Merge pull request #15483 from Bharat123rox/squeeze
[DOC] Mention behaviour of np.squeeze with one element
Diffstat (limited to 'numpy/core/fromnumeric.py')
-rw-r--r-- | numpy/core/fromnumeric.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index f3d3b8a92..ab45ddfe8 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -1445,7 +1445,8 @@ def squeeze(a, axis=None): squeezed : ndarray The input array, but with all or a subset of the dimensions of length 1 removed. This is always `a` itself - or a view into `a`. + or a view into `a`. Note that if all axes are squeezed, + the result is a 0d array and not a scalar. Raises ------ @@ -1472,6 +1473,15 @@ def squeeze(a, axis=None): ValueError: cannot select an axis to squeeze out which has size not equal to one >>> np.squeeze(x, axis=2).shape (1, 3) + >>> x = np.array([[1234]]) + >>> x.shape + (1, 1) + >>> np.squeeze(x) + array(1234) # 0d array + >>> np.squeeze(x).shape + () + >>> np.squeeze(x)[()] + 1234 """ try: |