-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: add mean keyword to std and var #24126
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
ENH: add mean keyword to std and var #24126
Conversation
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.
This seems a good solution! I also like that now one can put in something else than the mean from the same data (which is often useful). But see the important comment about subclasses, plus a lot of more nitpicky ones.
Note that I'm surprised MaskedArray
does not work. Did you try again? Could you explain the problem? And is this a new problem, or did the functions not work even before? If they worked before, it would be much nicer to get MaskedArray
right too.
I now added support for "mean" keyword on MaskedArrays. |
(numpy#24126 (comment)) The dispatcher returns all arguments that can, in principle, contain something that is an array and hence that, if not a regular ndarray, can allow the function to be dealt with another package (say, dask). Since mean can be an array, it should be added (most similar to where).
@charris The cygwin test failed, but from the reported error I guess it has little to do with my change. Will it run again automagically? |
I re-ran it manually. If it fails again we can ignore the failure. |
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.
Looks good, @mhvk already did all the review. Just a few nits about the release note and docstrings.
The output of the examples depends on platform and circumstances. Therefore testing based on example code gives errors:
Is there a method for handling this? |
Added: #doctest: +SKIP |
You could do something like
|
#doctest: +SKIP did the trick |
I think that issue #23741 can be closed. |
Replaces previous pull request #23889 (ENH: Introduce new functions mean_std and mean_var.) after triage review.
Often when the standard deviation is needed the mean is also needed; the same holds for the variance and the mean. With the current code the mean is then calculated twice, this can be prevented if the functions calculating the variance or the standard deviation can use a precalculated mean. See ticket #23741.
These changes can be largely independent from those for ticket #13199, which suggests reducing memory usage by avoiding storing data-mean in a separate intermediate array.
See also: discussion on the mailing list