-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
ENH: np.nanmean with weights #21375
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 stateme 8000 nt. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Has this feature been implemented yet? I'm trying to take a weighted nanmean of a list |
@itang1 I don't think so, but you can use my wrapper from sklearn, released recently:
|
Hey, have a draft PR for this change (#25474). Decided to go with adding an ignore_nan parameter to np.average as it seemed like the path of least resistance. Would love some feedback on this if anyone has the time. |
Looked into option a) since option b) was struck down. Problem is that weights need to also be added to np.mean as all the nan functions are required to have identical signatures to their non nan counterparts. Adding weights to np.mean is pretty hands on and seems above my ability. If anyone else wants to take this on, feel free. |
Proposed new feature or change:
My motivation comes from this PR in sklearn https://github.com/scikit-learn/scikit-learn/pull/23183/files#diff-b62de604fe871c9d2dcbfc799daf93b5bcebef1bf08341a0a7fc7562ba20b337R148, where I wrote:
The ideas would be to add this functionality to one of the two functions, i.e:
a) add weights to np.nanmean: https://numpy.org/doc/stable/reference/generated/numpy.nanmean.html
b) add option to ignore nan's for np.average : https://numpy.org/doc/stable/reference/generated/numpy.average.html
I'm aware of https://numpy.org/doc/stable/reference/generated/numpy.ma.average.html#numpy.ma.average but to be honest, I think it'd still be useful to implicitly indicate the mask with np.nan in the value, rather than having to create a masked array.
I'm happy to (at least try) do the PR myself, but would like some feedback on the idea / scope / api, and whether I missed some already existing method.
The text was updated successfully, but these errors were encountered: