fast_array_utils.stats¶
Statistics utilities for 2D arrays.
All of these allow you to specify an axis,
which allows you to choose whether to compute the statistic across rows, columns, or all elements.
- fast_array_utils.stats.is_constant(x: NDArray[Any] | types.CSBase | types.CupyArray, /, *, axis: None = None) bool¶
- fast_array_utils.stats.is_constant(x: NDArray[Any] | types.CSBase, /, *, axis: Literal[0, 1]) NDArray[np.bool]
- fast_array_utils.stats.is_constant(x: types.CupyArray, /, *, axis: Literal[0, 1]) types.CupyArray
- fast_array_utils.stats.is_constant(x: types.DaskArray, /, *, axis: Literal[0, 1] | None = None) types.DaskArray
Check whether values in array are constant.
- Parameters:
x – Array to check.
axis – Axis to reduce over.
- Returns:
Example
>>> import numpy as np >>> x = np.array([ ... [0, 1, 2], ... [0, 0, 0], ... ]) >>> is_constant(x) False >>> is_constant(x, axis=0) array([ True, False, False]) >>> is_constant(x, axis=1) array([False, True])
- fast_array_utils.stats.max(x: CpuArray | DiskArray, /, *, axis: None = None, keep_cupy_as_array: bool = False) np.number[Any]¶
- fast_array_utils.stats.max(x: CpuArray | DiskArray, /, *, axis: Literal[0, 1], keep_cupy_as_array: bool = False) NDArray[Any]
- fast_array_utils.stats.max(x: GpuArray, /, *, axis: None = None, keep_cupy_as_array: Literal[False] = False) np.number[Any]
- fast_array_utils.stats.max(x: GpuArray, /, *, axis: None, keep_cupy_as_array: Literal[True]) types.CupyArray
- fast_array_utils.stats.max(x: GpuArray, /, *, axis: Literal[0, 1], keep_cupy_as_array: bool = False) types.CupyArray
- fast_array_utils.stats.max(x: types.DaskArray, /, *, axis: Literal[0, 1] | None = None, keep_cupy_as_array: bool = False) types.DaskArray
Find the maximum along both or one axis.
- Parameters:
x – Array to find the maximum(s) in.
axis – Axis to reduce over.
- Returns:
If
axisisNone, then the maximum element is returned as a scalar.Otherwise, the maximum along the given axis is returned as a 1D array.
Example
>>> import numpy as np >>> x = np.array([ ... [0, 1, 2], ... [0, 0, 0], ... ]) >>> max(x) np.int64(2) >>> max(x, axis=0) array([0, 1, 2]) >>> max(x, axis=1) array([2, 0])
See also
- fast_array_utils.stats.mean(x: CpuArray | GpuArray | DiskArray, /, *, axis: None = None, dtype: DTypeLike | None = None) np.number[Any]¶
- fast_array_utils.stats.mean(x: CpuArray | DiskArray, /, *, axis: Literal[0, 1], dtype: DTypeLike | None = None) NDArray[np.number[Any]]
- fast_array_utils.stats.mean(x: GpuArray, /, *, axis: Literal[0, 1], dtype: DTypeLike | None = None) types.CupyArray
- fast_array_utils.stats.mean(x: types.DaskArray, /, *, axis: Literal[0, 1], dtype: ToDType[Any] | None = None) types.DaskArray
Mean over both or one axis.
- Parameters:
x – Array to calculate mean(s) for.
axis – Axis to reduce over.
- Returns:
If
axisisNone, then the sum over all elements is returned as a scalar.Otherwise, the sum over the given axis is returned as a 1D array.
Example
>>> import numpy as np >>> x = np.array([ ... [0, 1, 2], ... [0, 0, 0], ... ]) >>> mean(x) np.float64(0.5) >>> mean(x, axis=0) array([0. , 0.5, 1. ]) >>> mean(x, axis=1) array([1., 0.])
See also
- fast_array_utils.stats.mean_var(x: CpuArray | GpuArray, /, *, axis: None = None, correction: int = 0) tuple[np.float64, np.float64]¶
- fast_array_utils.stats.mean_var(x: CpuArray, /, *, axis: Literal[0, 1], correction: int = 0) tuple[NDArray[np.float64], NDArray[np.float64]]
- fast_array_utils.stats.mean_var(x: GpuArray, /, *, axis: Literal[0, 1], correction: int = 0) tuple[types.CupyArray, types.CupyArray]
- fast_array_utils.stats.mean_var(x: types.DaskArray, /, *, axis: Literal[0, 1] | None = None, correction: int = 0) tuple[types.DaskArray, types.DaskArray]
Mean and variance over both or one axis.
- Parameters:
x – Array to compute mean and variance for.
axis – Axis to reduce over.
correction – Degrees of freedom correction.
- Returns:
mean – See below:
var – If
axisisNone, the mean and variance over all elements are returned as scalars. Otherwise, the means and variances over the given axis are returned as 1D arrays.
Example
>>> import numpy as np >>> x = np.array([ ... [0, 1, 2], ... [0, 0, 0], ... ]) >>> mean_var(x) (np.float64(0.5), np.float64(0.5833333333333334)) >>> mean_var(x, axis=0) (array([0. , 0.5, 1. ]), array([0. , 0.25, 1. ])) >>> mean_var(x, axis=1) (array([1., 0.]), array([0.66666667, 0. ]))
See also
- fast_array_utils.stats.min(x: CpuArray | DiskArray, /, *, axis: None = None, keep_cupy_as_array: bool = False) np.number[Any]¶
- fast_array_utils.stats.min(x: CpuArray | DiskArray, /, *, axis: Literal[0, 1], keep_cupy_as_array: bool = False) NDArray[Any]
- fast_array_utils.stats.min(x: GpuArray, /, *, axis: None = None, keep_cupy_as_array: Literal[False] = False) np.number[Any]
- fast_array_utils.stats.min(x: GpuArray, /, *, axis: None, keep_cupy_as_array: Literal[True]) types.CupyArray
- fast_array_utils.stats.min(x: GpuArray, /, *, axis: Literal[0, 1], keep_cupy_as_array: bool = False) types.CupyArray
- fast_array_utils.stats.min(x: types.DaskArray, /, *, axis: Literal[0, 1] | None = None, keep_cupy_as_array: bool = False) types.DaskArray
Find the minimum along both or one axis.
- Parameters:
x – Array to find the minimum(s) in.
axis – Axis to reduce over.
- Returns:
If
axisisNone, then the minimum element is returned as a scalar.Otherwise, the minimum along the given axis is returned as a 1D array.
Example
>>> import numpy as np >>> x = np.array([ ... [0, 1, 2], ... [1, 1, 1], ... ]) >>> min(x) np.int64(0) >>> min(x, axis=0) array([0, 1, 1]) >>> min(x, axis=1) array([0, 1])
See also
- fast_array_utils.stats.sum(x: CpuArray | DiskArray, /, *, axis: None = None, dtype: DTypeLike | None = None, keep_cupy_as_array: bool = False) np.number[Any]¶
- fast_array_utils.stats.sum(x: CpuArray | DiskArray, /, *, axis: Literal[0, 1], dtype: DTypeLike | None = None, keep_cupy_as_array: bool = False) NDArray[Any]
- fast_array_utils.stats.sum(x: GpuArray, /, *, axis: None = None, dtype: DTypeLike | None = None, keep_cupy_as_array: Literal[False] = False) np.number[Any]
- fast_array_utils.stats.sum(x: GpuArray, /, *, axis: None = None, dtype: DTypeLike | None = None, keep_cupy_as_array: Literal[True]) types.CupyArray
- fast_array_utils.stats.sum(x: GpuArray, /, *, axis: Literal[0, 1], dtype: DTypeLike | None = None, keep_cupy_as_array: bool = False) types.CupyArray
- fast_array_utils.stats.sum(x: types.DaskArray, /, *, axis: Literal[0, 1] | None = None, dtype: DTypeLike | None = None, keep_cupy_as_array: bool = False) types.DaskArray
Sum over both or one axis.
- Parameters:
x – Array to sum up.
axis – Axis to reduce over.
- Returns:
If
axisisNone, then the sum over all elements is returned as a scalar.Otherwise, the sum over the given axis is returned as a 1D array.
Example
>>> import numpy as np >>> x = np.array([ ... [0, 1, 2], ... [0, 0, 0], ... ]) >>> sum(x) np.int64(3) >>> sum(x, axis=0) array([0, 1, 2]) >>> sum(x, axis=1) array([3, 0])
See also