MCPcopy Create free account
hub / github.com/numpy/numpy / test_density

Method test_density

numpy/lib/tests/test_histograms.py:42–72  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

40 assert_allclose(e, np.array([1., 2.]))
41
42 def test_density(self):
43 # Check that the integral of the density equals 1.
44 n = 100
45 v = np.random.rand(n)
46 a, b = histogram(v, density=True)
47 area = np.sum(a * np.diff(b))
48 assert_almost_equal(area, 1)
49
50 # Check with non-constant bin widths
51 v = np.arange(10)
52 bins = [0, 1, 3, 6, 10]
53 a, b = histogram(v, bins, density=True)
54 assert_array_equal(a, .1)
55 assert_equal(np.sum(a * np.diff(b)), 1)
56
57 # Test that passing False works too
58 a, b = histogram(v, bins, density=False)
59 assert_array_equal(a, [1, 2, 3, 4])
60
61 # Variable bin widths are especially useful to deal with
62 # infinities.
63 v = np.arange(10)
64 bins = [0, 1, 3, 6, np.inf]
65 a, b = histogram(v, bins, density=True)
66 assert_array_equal(a, [.1, .1, .1, 0.])
67
68 # Taken from a bug report from N. Becker on the numpy-discussion
69 # mailing list Aug. 6, 2010.
70 counts, dmy = np.histogram(
71 [1, 2, 3, 4], [0.5, 1.5, np.inf], density=True)
72 assert_equal(counts, [.25, 0])
73
74 def test_outliers(self):
75 # Check that outliers are not tallied

Callers

nothing calls this directly

Calls 5

histogramFunction · 0.90
assert_almost_equalFunction · 0.90
assert_array_equalFunction · 0.90
assert_equalFunction · 0.90
sumMethod · 0.45

Tested by

no test coverage detected