-
-
Notifications
You must be signed in to change notification settings - Fork 11k
ENH: Let numpy.size accept multiple axes. #29240
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
base: main
Are you sure you want to change the base?
Conversation
8f17ccf
to
5dfded8
Compare
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.
Thanks for this. The use-cases are probably a bit niche, but I'm sure that there are genuine use-cases for this, and the required changes are nice and subtle.
I left some comments about two edge-cases. It could help to add a quick example of this in the docstring. A release note might also be a good idea here, but it's probably a good idea to wait until everyone is happy, otherwise you risk having to change it a couple of times.
Oh and don't forget about the stubs :)
numpy/numpy/_core/fromnumeric.pyi
Line 1400 in 979b5c9
def size(a: ArrayLike, axis: int | None = ...) -> int: ... |
I don't mind putting this in, but the discussion did not actually point to why this is useful. It would have been nice to make |
@mattip This is useful for measuring the size of a multidimensional array with semantically-meaningful axes in a specific, nontrivial way. For example, I can get the pixel size of an image in HWC format via |
5dfded8
to
57fbe4b
Compare
Thanks. Personally i use |
57fbe4b
to
991148d
Compare
Fixes #29239.