MCPcopy Index your code
hub / github.com/numpy/numpy / test_density

Method test_density

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

Source from the content-addressed store, hash-verified

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