MCPcopy Index your code
hub / github.com/numpy/numpy / _ureduce

Function _ureduce

numpy/lib/_function_base_impl.py:3827–3906  ·  view source on GitHub ↗

Internal Function. Call `func` with `a` as first argument swapping the axes to use extended axis on functions that don't support it natively. Returns result and a.shape with axis dims set to 1. Parameters ---------- a : array_like Input array or object that can

(a, func, keepdims=False, **kwargs)

Source from the content-addressed store, hash-verified

3825
3826
3827def _ureduce(a, func, keepdims=False, **kwargs):
3828 """
3829 Internal Function.
3830 Call `func` with `a` as first argument swapping the axes to use extended
3831 axis on functions that don't support it natively.
3832
3833 Returns result and a.shape with axis dims set to 1.
3834
3835 Parameters
3836 ----------
3837 a : array_like
3838 Input array or object that can be converted to an array.
3839 func : callable
3840 Reduction function capable of receiving a single axis argument.
3841 It is called with `a` as first argument followed by `kwargs`.
3842 kwargs : keyword arguments
3843 additional keyword arguments to pass to `func`.
3844
3845 Returns
3846 -------
3847 result : tuple
3848 Result of func(a, **kwargs) and a.shape with axis dims set to 1
3849 which can be used to reshape the result to the same shape a ufunc with
3850 keepdims=True would produce.
3851
3852 """
3853 a = np.asanyarray(a)
3854 axis = kwargs.get('axis')
3855 out = kwargs.get('out')
3856
3857 if keepdims is np._NoValue:
3858 keepdims = False
3859
3860 nd = a.ndim
3861 if axis is not None:
3862 axis = _nx.normalize_axis_tuple(axis, nd)
3863
3864 if keepdims and out is not None:
3865 index_out = tuple(
3866 0 if i in axis else slice(None) for i in range(nd))
3867 kwargs['out'] = out[(Ellipsis, ) + index_out]
3868
3869 if len(axis) == 1:
3870 kwargs['axis'] = axis[0]
3871 else:
3872 keep = sorted(set(range(nd)) - set(axis))
3873 nkeep = len(keep)
3874
3875 def reshape_arr(a):
3876 # move axis that should not be reduced to front
3877 a = np.moveaxis(a, keep, range(nkeep))
3878 # merge reduced axis
3879 return a.reshape(a.shape[:nkeep] + (-1,))
3880
3881 a = reshape_arr(a)
3882
3883 weights = kwargs.get("weights")
3884 if weights is not None:

Callers 3

medianFunction · 0.90
medianFunction · 0.85
_quantile_uncheckedFunction · 0.85

Calls 4

sliceFunction · 0.85
reshape_arrFunction · 0.85
funcFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…