MCPcopy
hub / github.com/numpy/numpy / _quantile

Function _quantile

numpy/lib/_function_base_impl.py:4726–4915  ·  view source on GitHub ↗

Private function that doesn't support extended axis or keepdims. These methods are extended to this function using _ureduce. See nanpercentile for parameter usage. It computes the quantiles of the array for the given axis. A linear interpolation is performed based on the `method

(
    arr: "np.typing.ArrayLike",
    quantiles: np.ndarray,
    axis: int = -1,
    method: str = "linear",
    out: np.ndarray | None = None,
    weights: "np.typing.ArrayLike | None" = None,
    weak_q: bool = False,
)

Source from the content-addressed store, hash-verified

4724
4725
4726def _quantile(
4727 arr: "np.typing.ArrayLike",
4728 quantiles: np.ndarray,
4729 axis: int = -1,
4730 method: str = "linear",
4731 out: np.ndarray | None = None,
4732 weights: "np.typing.ArrayLike | None" = None,
4733 weak_q: bool = False,
4734) -> np.ndarray:
4735 """
4736 Private function that doesn't support extended axis or keepdims.
4737 These methods are extended to this function using _ureduce.
4738 See nanpercentile for parameter usage.
4739 It computes the quantiles of the array for the given axis.
4740 A linear interpolation is performed based on the `method`.
4741
4742 By default, the method is "linear" where alpha == beta == 1 which
4743 performs the 7th method of Hyndman&Fan.
4744 With "median_unbiased" we get alpha == beta == 1/3
4745 thus the 8th method of Hyndman&Fan.
4746 """
4747 # --- Setup
4748 arr = np.asanyarray(arr)
4749 values_count = arr.shape[axis]
4750 # The dimensions of `q` are prepended to the output shape, so we need the
4751 # axis being sampled from `arr` to be last.
4752 if axis != 0: # But moveaxis is slow, so only call it if necessary.
4753 arr = np.moveaxis(arr, axis, destination=0)
4754 supports_nans = (
4755 np.issubdtype(arr.dtype, np.inexact) or arr.dtype.kind in 'Mm'
4756 )
4757
4758 if weights is None:
4759 # --- Computation of indexes
4760 # Index where to find the value in the sorted array.
4761 # Virtual because it is a floating point value, not a valid index.
4762 # The nearest neighbours are used for interpolation
4763 try:
4764 method_props = _QuantileMethods[method]
4765 except KeyError:
4766 raise ValueError(
4767 f"{method!r} is not a valid method. Use one of: "
4768 f"{_QuantileMethods.keys()}") from None
4769 virtual_indexes = method_props["get_virtual_index"](values_count,
4770 quantiles)
4771 virtual_indexes = np.asanyarray(virtual_indexes)
4772
4773 if method_props["fix_gamma"] is None:
4774 supports_integers = True
4775 else:
4776 int_virtual_indices = np.issubdtype(virtual_indexes.dtype,
4777 np.integer)
4778 supports_integers = method == 'linear' and int_virtual_indices
4779
4780 if supports_integers:
4781 # No interpolation needed, take the points along axis
4782 if supports_nans:
4783 # may contain nan, which would sort to the end

Callers 1

_quantile_ureduce_funcFunction · 0.85

Calls 15

takeFunction · 0.90
_get_indexesFunction · 0.85
_get_gammaFunction · 0.85
_lerpFunction · 0.85
find_cdf_1dFunction · 0.85
reshapeMethod · 0.80
cumsumMethod · 0.80
astypeMethod · 0.80
itemMethod · 0.80
concatenateFunction · 0.50
keysMethod · 0.45
partitionMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…