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

Function _ravel_and_check_weights

numpy/lib/_histograms_impl.py:278–295  ·  view source on GitHub ↗

Check a and weights have matching shapes, and ravel both

(a, weights)

Source from the content-addressed store, hash-verified

276
277
278def _ravel_and_check_weights(a, weights):
279 """ Check a and weights have matching shapes, and ravel both """
280 a = np.asarray(a)
281
282 # Ensure that the array is a "subtractable" dtype
283 if a.dtype == np.bool:
284 msg = f"Converting input from {a.dtype} to {np.uint8} for compatibility."
285 warnings.warn(msg, RuntimeWarning, stacklevel=3)
286 a = a.astype(np.uint8)
287
288 if weights is not None:
289 weights = np.asarray(weights)
290 if weights.shape != a.shape:
291 raise ValueError(
292 'weights should have the same shape as a.')
293 weights = weights.ravel()
294 a = a.ravel()
295 return a, weights
296
297
298def _get_outer_edges(a, range):

Callers 2

histogram_bin_edgesFunction · 0.85
histogramFunction · 0.85

Calls 2

astypeMethod · 0.80
ravelMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…