Skip to content

Commit

Permalink
Merge pull request #8737 from eric-wieser/squeeze-expand-docs
Browse files Browse the repository at this point in the history
DOC: Mention that expand_dims and squeeze are inverses
  • Loading branch information
charris committed Apr 1, 2017
2 parents c3dd0e1 + f2b27fb commit c93201a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion numpy/core/fromnumeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,14 +1162,30 @@ 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]]])
>>> x.shape
(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)
"""
Expand Down
2 changes: 2 additions & 0 deletions numpy/lib/shape_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ def expand_dims(a, axis):
See Also
--------
squeeze : The inverse operation, removing singleton dimensions
reshape : Insert, remove, and combine dimensions, and resize existing ones
doc.indexing, atleast_1d, atleast_2d, atleast_3d
Examples
Expand Down

0 comments on commit c93201a

Please sign in to comment.