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.

redimslist of str, list or dict

One of out_dims or in_dims in {func}`~xarray_einstats.einops.rearrange` or {func}`~xarray_einstats.einops.reduce`.

allow_dict, allow_listbool, optional

Whether or not to allow lists or dicts as elements of redims. When processing in_dims for example we need the names of the variables to be decomposed so dicts are required and lists are not accepted.

expression_dimslist of str

A list with the names of the dimensions present in the out expression

output_dimslist of str

A list with the names of the dimensions present in the output. It differs from expression_dims because there might be dimensions being stacked.


The einops expression equivalent to the operations in redims pattern list.


Whenever we have groupings of dimensions (be it to decompose or to stack), expression_dims and output_dims differ:

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 )')