reduce#
- xarray_einstats.einops.reduce(da, pattern, reduction, pattern_in=None, **kwargs)[source]#
Expose einops.reduce with an xarray-like API.
It has two possible syntaxes which are independent and somewhat complementary.
- Parameters:
- da
xarray.DataArray Input array
- pattern
strorlistof [str,listordict] If pattern is a string, it uses the same syntax as einops with two caveats:
Unless splitting or stacking, you must use the actual dimension names.
When splitting or stacking you can use
(dim1 dim2)=dim. This is necessary for the left hand side as it identifies the dimension to split, and optional on the right hand side, if omitted the stacked dimension will be given a default name.
If pattern is not a string, then it must be a list where each of its elements is one of:
str,list(to stack those dimensions and give them an arbitrary name) ordict of {str: list}(to stack the dimensions indicated as values of the dictionary and name the resulting dimensions with the key).pattern is then interpreted as the output side of the einops pattern. See TODO for more details.
- reduction
strorcallable One of available reductions (‘min’, ‘max’, ‘sum’, ‘mean’, ‘prod’) by
einops.reduce, case-sensitive. Alternatively, a callablef(tensor, reduced_axes) -> tensorcan be provided.reduced_axesare passed as a list of int.- pattern_in
listof [strordict], optional The input pattern for the dimensions. It can only be provided if pattern is a
list. Also, note this is only necessary if you want to split some dimensions.The syntax and interpretation is the same as the case when pattern is a list, with the only difference that
listelements are not allowed, the same way that(dim1 dim2)=dimis required on the left hand side when using string- kwargs
dict, optional Passed to
xarray_einstats.einops.reduce
- da
- Returns:
See also
Notes
Unlike for general xarray objects, where dimension names can be hashable here dimension names are not recommended but required to be strings for both cases. Future releases however might support this when using lists as pattern, comment on GH#50 if you are interested in the feature or could help implement it.