MCPcopy
hub / github.com/numpy/numpy / _weights_are_valid

Function _weights_are_valid

numpy/lib/_function_base_impl.py:420–442  ·  view source on GitHub ↗

Validate weights array. We assume, weights is not None.

(weights, a, axis)

Source from the content-addressed store, hash-verified

418
419
420def _weights_are_valid(weights, a, axis):
421 """Validate weights array.
422
423 We assume, weights is not None.
424 """
425 wgt = np.asanyarray(weights)
426
427 # Sanity checks
428 if a.shape != wgt.shape:
429 if axis is None:
430 raise TypeError(
431 "Axis must be specified when shapes of a and weights "
432 "differ.")
433 if wgt.shape != tuple(a.shape[ax] for ax in axis):
434 raise ValueError(
435 "Shape of weights must be consistent with "
436 "shape of a along specified axis.")
437
438 # setup wgt to broadcast along axis
439 wgt = wgt.transpose(np.argsort(axis))
440 wgt = wgt.reshape(tuple((s if ax in axis else 1)
441 for ax, s in enumerate(a.shape)))
442 return wgt
443
444
445def _average_dispatcher(a, axis=None, weights=None, returned=None, *,

Callers 5

nanpercentileFunction · 0.90
nanquantileFunction · 0.90
averageFunction · 0.85
percentileFunction · 0.85
quantileFunction · 0.85

Calls 2

reshapeMethod · 0.80
argsortMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…