cmomy.wrap_reduce_vals#
- cmomy.wrap_reduce_vals(x, *y, mom, weight=None, axis=MISSING, mom_params=None, dim=MISSING, mom_dims=None, out=None, dtype=None, casting='same_kind', order=None, parallel=None, keep_attrs=None, apply_ufunc_kwargs=None)[source]#
Create wrapped object from values.
- Parameters:
x (array-like or
DataArray
orDataset
) – Values to reduce.*y (array-like or
DataArray
orDataset
) – Additional values (needed iflen(mom)==2
).y
has same type restrictions and broadcasting rules asweight
.mom (
int
ortuple
ofint
) – Order or moments. If integer or length one tuple, then moments are for a single variable. If length 2 tuple, then comoments of two variablesweight (array-like or
DataArray
orDataset
) –Optional weight. The type of
weight
must be “less than” the type ofx
.x
isDataset
:weight
can be aDataset
,DataArray
, or array-likex
is array-like:weight
can be array-like
In the case that
weight
is array-like, it must broadcast tox
using usual broadcasting rules (seenumpy.broadcast_to()
), with the following exceptions: Ifweight
is a 1d array of lengthx.shape[axis]]
, it will be formatted to broadcast along the other dimensions ofx
. For example, ifx
has shape(10, 2, 3)
andweight
has shape(10,)
, thenweight
will be converted to the broadcastable shape(10, 1, 1)
. Ifweight
is a scalar, it will be broadcast tox.shape
.axis (
int
) – Axis to reduce/sample along.dim (hashable) – Dimension to reduce/sample along.
mom_dims (hashable or
tuple
of hashable) – Name of moment dimensions. Defaults to("mom_0",)
formom_ndim==1
and(mom_0, mom_1)
formom_ndim==2
out (
ndarray
) – Optional output array. If specified, output will be a reference to this array. Note that if the output if method returns aDataset
, then this option is ignored.casting (
{'no', 'equiv', 'safe', 'same_kind', 'unsafe'}
, optional) –Controls what kind of data casting may occur.
’no’ means the data types should not be cast at all.
’equiv’ means only byte-order changes are allowed.
’safe’ means only casts which can preserve values are allowed.
’same_kind’ means only safe casts or casts within a kind, like float64 to float32, are allowed.
’unsafe’ (default) means any data conversions may be done.
order (
{"C", "F", "A", "K"}
, optional) – Order argument. Seenumpy.asarray()
.parallel (
bool
, optional) – IfTrue
, use parallel numbanumba.njit
ornumba.guvectorized
code if possible. IfNone
, use a heuristic to determine if should attempt to use parallel method.keep_attrs (
{"drop", "identical", "no_conflicts", "drop_conflicts", "override"}
orbool
, optional) –‘drop’ or False: empty attrs on returned xarray object.
’identical’: all attrs must be the same on every object.
’no_conflicts’: attrs from all objects are combined, any that have the same name must also have the same value.
’drop_conflicts’: attrs from all objects are combined, any that have the same name but different values are dropped.
’override’ or True: skip comparing and copy attrs from the first object to the result.
apply_ufunc_kwargs (dict-like) – Extra parameters to
xarray.apply_ufunc()
. One useful option ison_missing_core_dim
, which can take the value"copy"
(the default),"raise"
, or"drop"
and controls what to do with variables of aDataset
missing core dimensions. Other options arejoin
,dataset_join
,dataset_fill_value
, anddask_gufunc_kwargs
. Unlisted options are handled internally.
- Returns:
wrapped (
CentralMomentsArray
orCentralMomentsData
) – Wrapped object. If input data is anxarray
object, then returnCentralMomentsData
instance. Otherwise, returnCentralMomentsArray
instance.
See also
Examples
>>> import cmomy >>> rng = cmomy.default_rng(0) >>> x = rng.random((100, 3)) >>> da = cmomy.wrap_reduce_vals(x, axis=0, mom=2) >>> da <CentralMomentsArray(mom_ndim=1)> array([[1.0000e+02, 5.5313e-01, 8.8593e-02], [1.0000e+02, 5.5355e-01, 7.1942e-02], [1.0000e+02, 5.1413e-01, 1.0407e-01]])