blosc2.var#
- blosc2.var(ndarr: NDArray | NDField | C2Array | LazyExpr, axis: int | tuple[int] = None, dtype: dtype = None, ddof: int = 0, keepdims: bool = False, **kwargs: dict) ndarray | NDArray | int | float | bool #
Return the variance along the specified axis.
- Parameters:
ndarr¶ (NDArray or NDField or C2Array or LazyExpr) – The input array or expression.
axis¶ (int or tuple of ints, optional) – Axis or axes along which the variance is computed. The default is to compute the variance of the flattened array.
dtype¶ (np.dtype, optional) – Type to use in computing the variance. For integer inputs, the default is float32; for floating point inputs, it is the same as the input dtype.
ddof¶ (int, optional) – Means Delta Degrees of Freedom. The divisor used in calculations is N - ddof, where N represents the number of elements. By default, ddof is zero.
keepdims¶ (bool, optional) – If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
kwargs¶ (dict, optional) – Keyword arguments that are supported by the
empty()
constructor.
- Returns:
var_along_axis – The variance of the elements along the axis.
- Return type:
np.ndarray or NDArray or scalar
References
Examples
>>> import numpy as np >>> import blosc2 >>> # Create an instance of NDArray with some data >>> array = np.array([[1, 2, 3], [4, 5, 6]]) >>> nd_array = blosc2.asarray(array) >>> # Compute the variance of the entire array >>> var_all = blosc2.var(nd_array) >>> print("Variance of the entire array:", var_all) Variance of the entire array: 2.9166666666666665 >>> # Compute the variance along axis 0 (columns) >>> var_axis0 = blosc2.var(nd_array, axis=0) >>> print("Variance along axis 0:", var_axis0) Variance along axis 0: [2.25 2.25 2.25]