(self)
| 142 | assert_array_equal(edges, int_edges) |
| 143 | |
| 144 | def test_weights(self): |
| 145 | v = np.random.rand(100) |
| 146 | w = np.ones(100) * 5 |
| 147 | a, b = histogram(v) |
| 148 | na, nb = histogram(v, density=True) |
| 149 | wa, wb = histogram(v, weights=w) |
| 150 | nwa, nwb = histogram(v, weights=w, density=True) |
| 151 | assert_array_almost_equal(a * 5, wa) |
| 152 | assert_array_almost_equal(na, nwa) |
| 153 | |
| 154 | # Check weights are properly applied. |
| 155 | v = np.linspace(0, 10, 10) |
| 156 | w = np.concatenate((np.zeros(5), np.ones(5))) |
| 157 | wa, wb = histogram(v, bins=np.arange(11), weights=w) |
| 158 | assert_array_almost_equal(wa, w) |
| 159 | |
| 160 | # Check with integer weights |
| 161 | wa, wb = histogram([1, 2, 2, 4], bins=4, weights=[4, 3, 2, 1]) |
| 162 | assert_array_equal(wa, [4, 5, 0, 1]) |
| 163 | wa, wb = histogram( |
| 164 | [1, 2, 2, 4], bins=4, weights=[4, 3, 2, 1], density=True) |
| 165 | assert_array_almost_equal(wa, np.array([4, 5, 0, 1]) / 10. / 3. * 4) |
| 166 | |
| 167 | # Check weights with non-uniform bin widths |
| 168 | a, b = histogram( |
| 169 | np.arange(9), [0, 1, 3, 6, 10], |
| 170 | weights=[2, 1, 1, 1, 1, 1, 1, 1, 1], density=True) |
| 171 | assert_almost_equal(a, [.2, .1, .1, .075]) |
| 172 | |
| 173 | def test_exotic_weights(self): |
| 174 |
nothing calls this directly
no test coverage detected