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

Method test_exotic_weights

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

Source from the content-addressed store, hash-verified

171 assert_almost_equal(a, [.2, .1, .1, .075])
172
173 def test_exotic_weights(self):
174
175 # Test the use of weights that are not integer or floats, but e.g.
176 # complex numbers or object types.
177
178 # Complex weights
179 values = np.array([1.3, 2.5, 2.3])
180 weights = np.array([1, -1, 2]) + 1j * np.array([2, 1, 2])
181
182 # Check with custom bins
183 wa, wb = histogram(values, bins=[0, 2, 3], weights=weights)
184 assert_array_almost_equal(wa, np.array([1, 1]) + 1j * np.array([2, 3]))
185
186 # Check with even bins
187 wa, wb = histogram(values, bins=2, range=[1, 3], weights=weights)
188 assert_array_almost_equal(wa, np.array([1, 1]) + 1j * np.array([2, 3]))
189
190 # Decimal weights
191 from decimal import Decimal
192 values = np.array([1.3, 2.5, 2.3])
193 weights = np.array([Decimal(1), Decimal(2), Decimal(3)])
194
195 # Check with custom bins
196 wa, wb = histogram(values, bins=[0, 2, 3], weights=weights)
197 assert_array_almost_equal(wa, [Decimal(1), Decimal(5)])
198
199 # Check with even bins
200 wa, wb = histogram(values, bins=2, range=[1, 3], weights=weights)
201 assert_array_almost_equal(wa, [Decimal(1), Decimal(5)])
202
203 def test_no_side_effects(self):
204 # This is a regression test that ensures that values passed to

Callers

nothing calls this directly

Calls 2

histogramFunction · 0.90

Tested by

no test coverage detected