cumulatives¶
Advanced cumulative sum/productory/mean functions
-
xarray_extras.cumulatives.
cummean
(x: TV, dim: collections.abc.Hashable, skipna: Optional[bool] = None) → TV¶ - \[y_{i} = mean(x_{0}, x_{1}, ... x_{i})\]
- Parameters
dim (hashable) – dimension along which to calculate the mean
skipna (bool) – If True, skip missing values (as marked by NaN). By default, only skips missing values for float dtypes; other dtypes either do not have a sentinel missing value (int) or skipna=True has not been implemented (object, datetime64 or timedelta64).
- Returns
xarray object of the same type, dtype, and shape as x
-
xarray_extras.cumulatives.
compound_sum
(x: T, c: xarray.core.dataarray.DataArray, xdim: collections.abc.Hashable, cdim: collections.abc.Hashable) → T¶ Compound sum on arbitrary points of x along dim.
- Parameters
x –
xarray.DataArray
orxarray.Dataset
containing the data to be compoundedc (xarray.DataArray) – array where every row contains elements of x.coords[xdim] and is used to build a point of the output. The cells in the row are matched against x.coords[dim] and perform a sum. If different rows of c require different amounts of points from x, they must be padded on the right with NaN, NaT, or ‘’ (respectively for numbers, datetimes, and strings).
xdim (hashable) – dimension of x to acquire data from. The coord associated to it must be monotonic ascending.
cdim (hashable) – dimension of c that represent the vector of points to be compounded for every point of dim
- Returns
xarray object of the same type and dtype as x, with all dims from x and c except xdim and cdim.
example:
>>> x = xarray.DataArray( >>> [10, 20, 30], >>> dims=['x'], coords={'x': ['foo', 'bar', 'baz']}) >>> c = xarray.DataArray( >>> [['foo', 'baz', None], >>> ['bar', 'baz', 'baz']], >>> dims=['y', 'c'], coords={'y': ['new1', 'new2']}) >>> compound_sum(x, c, 'x', 'c') <xarray.DataArray (y: 2)> array([40, 80]) Coordinates: * y (y) <U4 'new1' 'new2'
-
xarray_extras.cumulatives.
compound_prod
(x: T, c: xarray.core.dataarray.DataArray, xdim: collections.abc.Hashable, cdim: collections.abc.Hashable) → T¶ Compound product among arbitrary points of x along dim See
compound_sum()
.
-
xarray_extras.cumulatives.
compound_mean
(x: T, c: xarray.core.dataarray.DataArray, xdim: collections.abc.Hashable, cdim: collections.abc.Hashable) → T¶ Compound mean among arbitrary points of x along dim See
compound_sum()
.