Skip to content
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

Merged
merged 1 commit into from Apr 1, 2017

Conversation

eric-wieser
Copy link
Member

[ci skip]'d

If #8735 might not be such a good idea, this gets most of the way there.

@@ -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
Copy link
Member

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
Copy link
Member

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".

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member

@seberg seberg Mar 5, 2017

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.

Copy link
Member Author

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

@charris charris merged commit c93201a into numpy:master Apr 1, 2017
@charris
Copy link
Member

charris commented Apr 1, 2017

Thanks Eric.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants