Skip to content
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

Add mass keyword to np.hist() #9921

Open
manuels opened this issue Oct 25, 2017 · 3 comments
Open

Add mass keyword to np.hist() #9921

manuels opened this issue Oct 25, 2017 · 3 comments

Comments

@manuels
Copy link

manuels commented Oct 25, 2017

A lot of people want to calculate the probability mass function using numpy.hist and are confused that it cannot do that.
It can however calculate the probability density function and #1043 did a great job by renaming normed to density.
Analogous to that, I propose to add a mass keyword that (if True) returns the probability mass function.

I would also implement this function, once I got positive feedback.

@ryanpeach
Copy link

We need to discuss the fact that normalization and binning are two independent factors of a histogram. PDF and PMF are impropper categories, as you can have binned continuous variables that are normalized by the area under the curve (PDF), those that aren't normalized at all (count), those that are normalized by the sum of the bin values (not really a PMF since it's binned), those that are normalized by the sum of the bin values for non continuous variables (Chevy, Volvo, Ford, etc. PMF), and probably others. Some tools apparently use a string input as the selection.

Ive been arguing with matplotlib about this. I don't think it's numpy's job to do this because normalization is easy to do mathematically post-hoc. It's just the graphing that's hard. It's their wrapper that makes it difficult to do intermediate steps on the process like normalization. But I digress.

@the-rccg
Copy link

Considering how frequently normalizations are used in histograms, it would make sense to me to allow for the functionality from simply a convenience point of view. Sure an extra line isn't a big deal once, but it adds up and the current implementation can be frustrating when looking for norm and realizing the parameter does not do what you need it to. Personally, I'm in favor of a norm_type parameter rather than adding a new one.

It should be noted though, that Matplotlib accepts the return structure of np.histogram directly as inputs to plot/bar/etc. Things become a little more troubling when working with Pandas DataFrames, since you have to manually slice them, run through np.histogram, then plot, but it's also doable.

Bottom line, implementing a count/sum/pmf normalization into np.histogram is trivial (one argument against it), but would provide convenience in modules building upon it.

@eric-wieser
Copy link
Member

eric-wieser commented Jun 13, 2018

There's a lot of discussion at matplotlib/matplotlib#10398 about adding such a keyword that might be worth reviewing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants