8000 Incorrect histogramdd behavior with masked arrays · Issue #5363 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content
Incorrect histogramdd behavior with masked arrays #5363
@bnordgren

Description

@bnordgren

Summing over the histogram should always give the number of non-masked records when no weighting is used. As shown below, the sum is reduced, but not by the correct amount. Calling the "compressed()" method and reshaping before running the histogram produces correct results.

The following uses numpy 1.8.1.

 x = ma.arange(300).reshape(100,3)

In [5]: print x[:,0].count()
100

In [6]: H,e = np.histogramdd(x)

In [7]: H.sum()
Out[7]: 100.0

In [8]: for i in range(10) : 
   ...:     x[i*i,:]=ma.masked
   ...:     

In [9]: print x[:,0].count()
90

In [10]: H,e = np.histogramdd(x)

In [11]: H.sum()
Out[11]: 98.0

x = x.compressed().reshape(90,3)

H,e = np.histogramdd(x)

H.sum()
Out[14]: 90.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0