summaryrefslogtreecommitdiff
path: root/numpy/core/fromnumeric.py
diff options
context:
space:
mode:
authorBharat Raghunathan <bharatraghunthan9767@gmail.com>2020-02-01 15:51:19 +0530
committerBharat Raghunathan <bharatraghunthan9767@gmail.com>2020-02-01 15:51:19 +0530
commit218f38fb6dc34cb9d9ffe7652800f9deee1de4d6 (patch)
tree406a94c3bbe6e2b95fbc3cef51ef17b57b53dd2f /numpy/core/fromnumeric.py
parent42730767439795c98ab5e9f5e47c90c661b2fe46 (diff)
downloadnumpy-218f38fb6dc34cb9d9ffe7652800f9deee1de4d6.tar.gz
[DOC] Mention special case of np.squeeze with one element
Diffstat (limited to 'numpy/core/fromnumeric.py')
-rw-r--r--numpy/core/fromnumeric.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py
index f3d3b8a92..874f951ae 100644
--- a/numpy/core/fromnumeric.py
+++ b/numpy/core/fromnumeric.py
@@ -1438,7 +1438,9 @@ def squeeze(a, axis=None):
Selects a subset of the single-dimensional entries in the
shape. If an axis is selected with shape entry greater than
- one, an error is raised.
+ one, an error is raised. Note that when applied to an array
+ `a` with one element and no axis argument, it returns a
+ wrapped scalar of no shape containing the element in `a`.
Returns
-------
@@ -1472,6 +1474,17 @@ 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)
+ >>> np.squeeze(x).shape
+ ()
+ >>> np.squeeze(x)[0]
+ Traceback (most recent call last):
+ ...
+ IndexError: too many indices for array
"""
try: