process_pattern_list¶
- xarray_einstats.einops.process_pattern_list(redims, handler, allow_dict=True, allow_list=True)[source]¶
Process a pattern list and convert it to an einops expression using placeholders.
- Parameters:
- redims
listof (hashable orlistordict) One of
out_dimsorin_dimsin {func}`~xarray_einstats.einops.rearrange` or {func}`~xarray_einstats.einops.reduce`.- handler
DimHandler - allow_dict, allow_listbool, optional
Whether or not to allow lists or dicts as elements of
redims. When processingin_dimsfor example we need the names of the variables to be decomposed so dicts are required and lists are not accepted.
- redims
- Returns:
- expression_dims
listofstr A list with the names of the dimensions present in the out expression
- output_dims
listofstr A list with the names of the dimensions present in the output. It differs from
expression_dimsbecause there might be dimensions being stacked.- pattern
str The einops expression equivalent to the operations in redims pattern list.
- expression_dims
Examples
Whenever we have groupings of dimensions (be it to decompose or to stack),
expression_dimsandoutput_dimsdiffer:from xarray_einstats.einops import process_pattern_list, DimHandler handler = DimHandler() process_pattern_list(["a", {"b": ["c", "d"]}, ["e", "f", "g"]], handler)
(['a', 'c', 'd', 'e', 'f', 'g'], ['a', 'b', 'e-f-g'], 'd0 ( d1 d2 ) ( d3 d4 d5 )')