question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH: Add a where argument to np.mean

See original GitHub issue

This 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:closed
  • Created 3 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
sgassecommented, Mar 27, 2020

@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 calculating rcount 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?

0reactions
mtsokolcommented, Mar 5, 2021

Hi! I’ve been porting this enhancement to jax and just wanted to ask if such error with where keyword is expected: https://github.com/numpy/numpy/issues/18552 Thank you for any advice!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found