def test_ndbincount(): def check(expected): npt.assert_equal(bc[0, 0], expected[0]) npt.assert_equal(bc[0, 1], expected[1]) npt.assert_equal(bc[1, 0], expected[2]) npt.assert_equal(bc[2, 2], expected[3]) x = np.array([[0, 0], [0, 0], [0, 1], [0, 1], [1, 0], [2, 2]]).T expected = [2, 2, 1, 1] # count occurrences in x bc = ndbincount(x) npt.assert_equal(bc.shape, (3, 3)) check(expected) # pass in shape bc = ndbincount(x, shape=(4, 5)) npt.assert_equal(bc.shape, (4, 5)) check(expected) # pass in weights weights = np.arange(6.) weights[-1] = 1.23 expeceted = [1., 5., 4., 1.23] bc = ndbincount(x, weights=weights) check(expeceted) # raises an error if shape is too small npt.assert_raises(ValueError, ndbincount, x, None, (2, 2))
def test_ndbincount(): def check(expected): assert_equal(bc[0, 0], expected[0]) assert_equal(bc[0, 1], expected[1]) assert_equal(bc[1, 0], expected[2]) assert_equal(bc[2, 2], expected[3]) x = np.array([[0, 0], [0, 0], [0, 1], [0, 1], [1, 0], [2, 2]]).T expected = [2, 2, 1, 1] # count occurrences in x bc = ndbincount(x) assert_equal(bc.shape, (3, 3)) check(expected) # pass in shape bc = ndbincount(x, shape=(4, 5)) assert_equal(bc.shape, (4, 5)) check(expected) # pass in weights weights = np.arange(6.) weights[-1] = 1.23 expeceted = [1., 5., 4., 1.23] bc = ndbincount(x, weights=weights) check(expeceted) # raises an error if shape is too small assert_raises(ValueError, ndbincount, x, None, (2, 2))