diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2018-06-18 17:08:53 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-18 17:08:53 -0600 |
commit | 717840c91029ac0680110838eec0103d23ccb32c (patch) | |
tree | ea69ec215fe71a58160bf5c2b339adcc22b8c748 /numpy/lib/tests | |
parent | c74ce40305200704c71133ca53da5944d27e8980 (diff) | |
parent | 914aabf07548ee3ddf5f3795177273d435a38c14 (diff) | |
download | numpy-717840c91029ac0680110838eec0103d23ccb32c.tar.gz |
Merge pull request #11373 from eric-wieser/histogramdd-density
TST: Show that histogramdd's normed argument is histogram's density
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r-- | numpy/lib/tests/test_histograms.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_histograms.py b/numpy/lib/tests/test_histograms.py index adaa7e3bd..9bea2aca8 100644 --- a/numpy/lib/tests/test_histograms.py +++ b/numpy/lib/tests/test_histograms.py @@ -703,3 +703,39 @@ class TestHistogramdd(object): hist, edges = histogramdd((x, y), bins=(x_edges, y_edges)) assert_equal(hist[0, 0], 1) + + def test_normed_non_uniform_2d(self): + # Defines the following grid: + # + # 0 2 8 + # 0+-+-----+ + # + | + + # + | + + # 6+-+-----+ + # 8+-+-----+ + x_edges = np.array([0, 2, 8]) + y_edges = np.array([0, 6, 8]) + relative_areas = np.array([ + [3, 9], + [1, 3]]) + + # ensure the number of points in each region is proportional to its area + x = np.array([1] + [1]*3 + [7]*3 + [7]*9) + y = np.array([7] + [1]*3 + [7]*3 + [1]*9) + + # sanity check that the above worked as intended + hist, edges = histogramdd((y, x), bins=(y_edges, x_edges)) + assert_equal(hist, relative_areas) + + # resulting histogram should be uniform, since counts and areas are propotional + hist, edges = histogramdd((y, x), bins=(y_edges, x_edges), normed=True) + assert_equal(hist, 1 / (8*8)) + + def test_normed_non_uniform_1d(self): + # compare to histogram to show the results are the same + v = np.arange(10) + bins = np.array([0, 1, 3, 6, 10]) + hist, edges = histogram(v, bins, density=True) + hist_dd, edges_dd = histogramdd((v,), (bins,), normed=True) + assert_equal(hist, hist_dd) + assert_equal(edges, edges_dd[0]) |