8000 np.hist: needs to be enabled for masked arrays (Trac #1214) · Issue #1812 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

np.hist: needs to be enabled for masked arrays (Trac #1214) #1812

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

Open
thouis opened this issue Oct 19, 2012 · 7 comments
Open

np.hist: needs to be enabled for masked arrays (Trac #1214) #1812

thouis opened this issue Oct 19, 2012 · 7 comments

Comments

@thouis
Copy link
Contributor
thouis commented Oct 19, 2012

Original ticket http://projects.scipy.org/numpy/ticket/1214 on 2009-09-01 by @timmie, assigned to @pierregm.

In R_project:

Note: values is my dataset

### masking zeros
values_mask=ifelse(values==0, NA, (values))

# http://stat.ethz.ch/R-manual/R-patched/library/stats/html/ecdf.html
plot(ecdf(values_mask), main="Emprical cumulative distribution function",
do.points=F, xlab='Data Values')

There masking the zeros has an effect.
With numpy not.

@thouis
Copy link
Contributor Author
thouis commented Oct 19, 2012

@timmie wrote on 2009-09-24

please send me changes for review.
I am not sure of this is not already supported and I was just using in wrongly.

@thouis
Copy link
Contributor Author
thouis commented Oct 19, 2012

Milestone changed to Unscheduled by @mwiebe on 2011-03-24

@thouis
Copy link
Contributor Author
thouis commented Oct 19, 2012

@rgommers wrote on 2011-04-02

This is an enhancement request. Should not be changed in numpy.histogram, and there is no numpy.ma.histogram.

@cancan101
Copy link
Contributor
cancan101 commented Jun 16, 2016

I think this is the same issue I am seeing, but I will post some example code:

arr = np.ones((10,))
arr[3] = 0
np.histogram(np.ma.masked_equal(arr, 0))

yields the 0 still being there:

(array([1, 0, 0, 0, 0, 0, 0, 0, 0, 9]),
 array([ 0. ,  0.1,  0.2,  0.3,  0.4,  0.5,  0.6,  0.7,  0.8,  0.9,  1. ]))

whereas min works: np.min(np.ma.masked_equal(arr, 0)) >> 1.0.

@charris
Copy link
Member
charris commented Jun 16, 2016

I expect min calls the masked array method. There is no histogram method for array, masked or otherwise.

@cancan101
Copy link
Contributor

Shouldn't there at least be a warning to the user if a masked array is passed into a function that doesn't handle the masked array and just silently uses the underlying data?

@njsmith
Copy link
Member
njsmith commented Jun 16, 2016

@cancan101: that might make sense, but it's fundamentally impossible to do in a reliable way given np.ma's design. (Specifically, it uses subclassing but massively violates the Liskov substitution principle.) Unfortunately np.ma has a number of these kinds of problems that aren't really fixable, which is why many of us strongly recommend that it not be used in new code.

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

No branches or pull requests

5 participants
0