(self)
| 647 | class TestHistogramdd: |
| 648 | |
| 649 | def test_simple(self): |
| 650 | x = np.array([[-.5, .5, 1.5], [-.5, 1.5, 2.5], [-.5, 2.5, .5], |
| 651 | [.5, .5, 1.5], [.5, 1.5, 2.5], [.5, 2.5, 2.5]]) |
| 652 | H, edges = histogramdd(x, (2, 3, 3), |
| 653 | range=[[-1, 1], [0, 3], [0, 3]]) |
| 654 | answer = np.array([[[0, 1, 0], [0, 0, 1], [1, 0, 0]], |
| 655 | [[0, 1, 0], [0, 0, 1], [0, 0, 1]]]) |
| 656 | assert_array_equal(H, answer) |
| 657 | |
| 658 | # Check normalization |
| 659 | ed = [[-2, 0, 2], [0, 1, 2, 3], [0, 1, 2, 3]] |
| 660 | H, edges = histogramdd(x, bins=ed, density=True) |
| 661 | assert_(np.all(H == answer / 12.)) |
| 662 | |
| 663 | # Check that H has the correct shape. |
| 664 | H, edges = histogramdd(x, (2, 3, 4), |
| 665 | range=[[-1, 1], [0, 3], [0, 4]], |
| 666 | density=True) |
| 667 | answer = np.array([[[0, 1, 0, 0], [0, 0, 1, 0], [1, 0, 0, 0]], |
| 668 | [[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 1, 0]]]) |
| 669 | assert_array_almost_equal(H, answer / 6., 4) |
| 670 | # Check that a sequence of arrays is accepted and H has the correct |
| 671 | # shape. |
| 672 | z = [np.squeeze(y) for y in np.split(x, 3, axis=1)] |
| 673 | H, edges = histogramdd( |
| 674 | z, bins=(4, 3, 2), range=[[-2, 2], [0, 3], [0, 2]]) |
| 675 | answer = np.array([[[0, 0], [0, 0], [0, 0]], |
| 676 | [[0, 1], [0, 0], [1, 0]], |
| 677 | [[0, 1], [0, 0], [0, 0]], |
| 678 | [[0, 0], [0, 0], [0, 0]]]) |
| 679 | assert_array_equal(H, answer) |
| 680 | |
| 681 | Z = np.zeros((5, 5, 5)) |
| 682 | Z[list(range(5)), list(range(5)), list(range(5))] = 1. |
| 683 | H, edges = histogramdd([np.arange(5), np.arange(5), np.arange(5)], 5) |
| 684 | assert_array_equal(H, Z) |
| 685 | |
| 686 | def test_shape_3d(self): |
| 687 | # All possible permutations for bins of different lengths in 3D. |
nothing calls this directly
no test coverage detected