(self)
| 608 | class TestHistogramdd: |
| 609 | |
| 610 | def test_simple(self): |
| 611 | x = np.array([[-.5, .5, 1.5], [-.5, 1.5, 2.5], [-.5, 2.5, .5], |
| 612 | [.5, .5, 1.5], [.5, 1.5, 2.5], [.5, 2.5, 2.5]]) |
| 613 | H, edges = histogramdd(x, (2, 3, 3), |
| 614 | range=[[-1, 1], [0, 3], [0, 3]]) |
| 615 | answer = np.array([[[0, 1, 0], [0, 0, 1], [1, 0, 0]], |
| 616 | [[0, 1, 0], [0, 0, 1], [0, 0, 1]]]) |
| 617 | assert_array_equal(H, answer) |
| 618 | |
| 619 | # Check normalization |
| 620 | ed = [[-2, 0, 2], [0, 1, 2, 3], [0, 1, 2, 3]] |
| 621 | H, edges = histogramdd(x, bins=ed, density=True) |
| 622 | assert_(np.all(H == answer / 12.)) |
| 623 | |
| 624 | # Check that H has the correct shape. |
| 625 | H, edges = histogramdd(x, (2, 3, 4), |
| 626 | range=[[-1, 1], [0, 3], [0, 4]], |
| 627 | density=True) |
| 628 | answer = np.array([[[0, 1, 0, 0], [0, 0, 1, 0], [1, 0, 0, 0]], |
| 629 | [[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 1, 0]]]) |
| 630 | assert_array_almost_equal(H, answer / 6., 4) |
| 631 | # Check that a sequence of arrays is accepted and H has the correct |
| 632 | # shape. |
| 633 | z = [np.squeeze(y) for y in np.split(x, 3, axis=1)] |
| 634 | H, edges = histogramdd( |
| 635 | z, bins=(4, 3, 2), range=[[-2, 2], [0, 3], [0, 2]]) |
| 636 | answer = np.array([[[0, 0], [0, 0], [0, 0]], |
| 637 | [[0, 1], [0, 0], [1, 0]], |
| 638 | [[0, 1], [0, 0], [0, 0]], |
| 639 | [[0, 0], [0, 0], [0, 0]]]) |
| 640 | assert_array_equal(H, answer) |
| 641 | |
| 642 | Z = np.zeros((5, 5, 5)) |
| 643 | Z[list(range(5)), list(range(5)), list(range(5))] = 1. |
| 644 | H, edges = histogramdd([np.arange(5), np.arange(5), np.arange(5)], 5) |
| 645 | assert_array_equal(H, Z) |
| 646 | |
| 647 | def test_shape_3d(self): |
| 648 | # All possible permutations for bins of different lengths in 3D. |
nothing calls this directly
no test coverage detected