ENH: Add a where argument to np.mean
See original GitHub issueThis would match and be implemented via the where
argument in np.sum
.
Most of the work here comes from implementing np.core._methods._count_reduce_items
correctly to handle the where argument.
Perhaps worth fixing #15817 first.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (11 by maintainers)
Top Results From Across the Web
How to use the NumPy mean function - Sharp Sight
This tutorial will show you how to use the NumPy mean function, which you'll often see in code as numpy.mean or np.mean.
Read more >numpy.mean — NumPy v1.24 Manual
Compute the arithmetic mean along the specified axis. Returns the average of the array elements. The average is taken over the flattened array...
Read more >Supported NumPy features - Numba
Numba excels at generating code that executes on top of NumPy arrays. ... This means that it is possible to implement ufuncs and...
Read more >jax.numpy package - JAX documentation - Read the Docs
For this reason, JAX adds an optional size argument to such functions which may be specified ... Compute the weighted average along the...
Read more >Version 1.0.2 — scikit-learn 1.2.0 documentation
Version 1.0.0 of scikit-learn requires python 3.7+, numpy 1.14.6+ and scipy 1.1.0+. ... Enhancement Adds **predict_params keyword argument to compose.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@eric-wieser sure, I just did not want to waste CI resources for a PR that I know would fail the checks.
You are right that speed is a limitation. In this commit, I catch the case that
where
is just a boolean and do not initialize the logical mask in that case. This gives a good speedup for cases where the parameter is not set explicitly. I have also added a few test cases and made sure to pass all other tests without changing them.I think optimization potential lies in the ‘in between’ cases: When
where
is a broadcastable array that is much smaller than the array of which to calculate the mean. Maybe I can find an abstract way of calculatingrcount
for those cases without a mask.Other than that, do you think there is a much faster way of calculating the mean in case a dense mask is given as
where
?Hi! I’ve been porting this enhancement to
jax
and just wanted to ask if such error withwhere
keyword is expected: https://github.com/numpy/numpy/issues/18552 Thank you for any advice!