get_default_dims¶
- xarray_einstats.stats.get_default_dims(dims)[source]¶
Get default dims on which to perfom an operation.
Whenever a function from
xarray_einstats.statsis called withdims=None(the default) this function is called to choose the default dims on which to operate out of the list with all the dims present.This function is thought to be monkeypatched by domain specific applications as shown in the examples.
- Parameters:
- Returns:
Examples
The
xarray_einstatsdefault behaviour is operating (averaging in this case) over all dimensions present in the input DataArray:from xarray_einstats import stats, tutorial da = tutorial.generate_mcmc_like_dataset(3)["mu"] stats.hmean(da)
<xarray.DataArray 'mu' ()> Size: 8B 0.1086
Here we show how to monkeypatch
get_default_dimsto get a different default behaviour. If you usexarray_einstatsand {doc}`arviz:index` to work with MCMC results, operating over chain and dim only might be a better default:def get_default_dims(dims): out = [dim for dim in ("chain", "draw") if dim in dims] if not out: # if chain nor draw are present fall back to all dims return dims return out stats.get_default_dims = get_default_dims stats.hmean(da)
<xarray.DataArray 'mu' (team: 6)> Size: 48B 0.03888 0.3158 0.0665 0.2233 0.2556 0.3426 Coordinates: * team (team) <U1 24B 'a' 'b' 'c' 'd' 'e' 'f'
You can still use
dimsexplicitly to average over any custom dimensionstats.hmean(da, dims="team")
<xarray.DataArray 'mu' (chain: 4, draw: 10)> Size: 320B 0.3059 0.1958 0.6869 0.01057 0.1915 ... 0.4187 0.05455 0.7643 0.5093 0.4906 Coordinates: * chain (chain) int64 32B 0 1 2 3 * draw (draw) int64 80B 0 1 2 3 4 5 6 7 8 9