diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2017-04-01 13:43:21 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-01 13:43:21 -0600 |
commit | c93201acabd010bcd15464d058faa02da207a292 (patch) | |
tree | 46158c0c014835ce62bdb10d81e0cb3d62fd7454 /numpy/core/fromnumeric.py | |
parent | c3dd0e134b1c354322fc360a0c747b27c62db9c9 (diff) | |
parent | f2b27fb90809bdf464e66b9f3be8037e9a72c0f7 (diff) | |
download | numpy-c93201acabd010bcd15464d058faa02da207a292.tar.gz |
Merge pull request #8737 from eric-wieser/squeeze-expand-docs
DOC: Mention that expand_dims and squeeze are inverses
Diffstat (limited to 'numpy/core/fromnumeric.py')
-rw-r--r-- | numpy/core/fromnumeric.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 4309277ad..a8c2fd2fb 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -1162,6 +1162,16 @@ def squeeze(a, axis=None): dimensions of length 1 removed. This is always `a` itself or a view into `a`. + Raises + ------ + ValueError + If `axis` is not `None`, and an axis being squeezed is not of length 1 + + See Also + -------- + expand_dims : The inverse operation, adding singleton dimensions + reshape : Insert, remove, and combine dimensions, and resize existing ones + Examples -------- >>> x = np.array([[[0], [1], [2]]]) @@ -1169,7 +1179,13 @@ def squeeze(a, axis=None): (1, 3, 1) >>> np.squeeze(x).shape (3,) - >>> np.squeeze(x, axis=(2,)).shape + >>> np.squeeze(x, axis=0).shape + (3, 1) + >>> np.squeeze(x, axis=1).shape + Traceback (most recent call last): + ... + ValueError: cannot select an axis to squeeze out which has size not equal to one + >>> np.squeeze(x, axis=2).shape (1, 3) """ |