ENH: Let numpy.size accept multiple axes.#29240
Conversation
8f17ccf to
5dfded8
Compare
jorenham
left a comment
There was a problem hiding this comment.
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
|
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
991148d to
328008c
Compare
|
Thanks @carlosgmartin, I don't know if I think it's very useful, but I think that places that accept axis and multiple make clearly sense and is simple, then it's good to just do it. |
|
@seberg In addition to #29240 (comment), this is needed by reductions like Thus the endpoint of the chain |
I don't like |
|
The non-masked path could perhaps reuse the new |
* Let numpy.size accept multiple axes. * Apply suggestions from code review --------- Co-authored-by: Sebastian Berg <[email protected]>
Fixes #29239.