New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOC: Mention that expand_dims and squeeze are inverses #8737
Conversation
numpy/core/fromnumeric.py
Outdated
@@ -1162,6 +1162,10 @@ def squeeze(a, axis=None): | |||
dimensions of length 1 removed. This is always `a` itself | |||
or a view into `a`. | |||
|
|||
See Also | |||
-------- | |||
expand_dims : The inverse operation, adding singleton dimensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not quite the inverse, as it only inserts one axis at a time.
@@ -255,6 +255,7 @@ def expand_dims(a, axis): | |||
|
|||
See Also | |||
-------- | |||
squeeze : The inverse operation, removing singleton dimensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, "removes all singleton dimensions".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I mean here is that np.squeeze(arr, axis=a)
and np.expand_dims(arr, axis=a)
are inverses. I guess this only applies to one of the two overloads
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might also mention reshape
in both contexts as it allows adding and removing axis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally like indexing a lot for this both of this too, unless it gets very clunky with counting :
. EDIT: Though I guess I admit that for squeezing, indexing does not give the information that there really is only one element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charris: Added comments about reshape
75d54a2
to
f2b27fb
Compare
Thanks Eric. |
[ci skip]'d
If #8735 might not be such a good idea, this gets most of the way there.