Reduce this dataset by applying `func` along some dimension(s). Parameters ---------- func : callable Function which can be called in the form `f(x, axis=axis, **kwargs)` to return the result of reducing an np.ndarray over an integer value
(
self,
func: Callable,
dim: Dims = None,
*,
keep_attrs: bool | None = None,
keepdims: bool = False,
numeric_only: bool = False,
**kwargs: Any,
)
| 6809 | return out |
| 6810 | |
| 6811 | def reduce( |
| 6812 | self, |
| 6813 | func: Callable, |
| 6814 | dim: Dims = None, |
| 6815 | *, |
| 6816 | keep_attrs: bool | None = None, |
| 6817 | keepdims: bool = False, |
| 6818 | numeric_only: bool = False, |
| 6819 | **kwargs: Any, |
| 6820 | ) -> Self: |
| 6821 | """Reduce this dataset by applying `func` along some dimension(s). |
| 6822 | |
| 6823 | Parameters |
| 6824 | ---------- |
| 6825 | func : callable |
| 6826 | Function which can be called in the form |
| 6827 | `f(x, axis=axis, **kwargs)` to return the result of reducing an |
| 6828 | np.ndarray over an integer valued axis. |
| 6829 | dim : str, Iterable of Hashable or None, optional |
| 6830 | Dimension(s) over which to apply `func`. By default `func` is |
| 6831 | applied over all dimensions. |
| 6832 | keep_attrs : bool or None, optional |
| 6833 | If True (default), the dataset's attributes (`attrs`) will be copied from |
| 6834 | the original object to the new one. If False, the new |
| 6835 | object will be returned without attributes. |
| 6836 | keepdims : bool, default: False |
| 6837 | If True, the dimensions which are reduced are left in the result |
| 6838 | as dimensions of size one. Coordinates that use these dimensions |
| 6839 | are removed. |
| 6840 | numeric_only : bool, default: False |
| 6841 | If True, only apply ``func`` to variables with a numeric dtype. |
| 6842 | **kwargs : Any |
| 6843 | Additional keyword arguments passed on to ``func``. |
| 6844 | |
| 6845 | Returns |
| 6846 | ------- |
| 6847 | reduced : Dataset |
| 6848 | Dataset with this object's DataArrays replaced with new DataArrays |
| 6849 | of summarized data and the indicated dimension(s) removed. |
| 6850 | |
| 6851 | Examples |
| 6852 | -------- |
| 6853 | |
| 6854 | >>> dataset = xr.Dataset( |
| 6855 | ... { |
| 6856 | ... "math_scores": ( |
| 6857 | ... ["student", "test"], |
| 6858 | ... [[90, 85, 92], [78, 80, 85], [95, 92, 98]], |
| 6859 | ... ), |
| 6860 | ... "english_scores": ( |
| 6861 | ... ["student", "test"], |
| 6862 | ... [[88, 90, 92], [75, 82, 79], [93, 96, 91]], |
| 6863 | ... ), |
| 6864 | ... }, |
| 6865 | ... coords={ |
| 6866 | ... "student": ["Alice", "Bob", "Charlie"], |
| 6867 | ... "test": ["Test 1", "Test 2", "Test 3"], |
| 6868 | ... }, |