{"id":2846,"library":"xarray-einstats","title":"xarray-einstats","description":"xarray-einstats is a Python library that provides a high-level API to combine the symbolic array manipulation of `einstats` with `xarray`'s labeled dimensions for statistical operations and linear algebra. It aims to simplify common data analysis tasks on `xarray.DataArray` and `xarray.Dataset` objects, enabling operations like reduction, broadcasting, and reshaping with `einops`-like patterns. The current version is 0.10.0, and it generally follows an irregular release cadence, with updates typically driven by new features or important bug fixes.","status":"active","version":"0.10.0","language":"en","source_language":"en","source_url":"https://github.com/astropenguin/xarray-einstats","tags":["xarray","einstats","statistics","linear algebra","array programming","data analysis"],"install":[{"cmd":"pip install xarray-einstats","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for labeled array functionality (>=2024.2.0)","package":"xarray","optional":false},{"reason":"Core dependency for `einops`-like statistical operations (>=0.7.0)","package":"einstats","optional":false},{"reason":"Numerical computing foundation (>=1.25.0)","package":"numpy","optional":false},{"reason":"Scientific computing functions, used by some statistical operations (>=1.11.0)","package":"scipy","optional":false}],"imports":[{"note":"The primary module for statistical functions.","symbol":"stats","correct":"import xarray_einstats.stats as xestats"},{"note":"A direct import for a specific statistical function.","symbol":"mean","correct":"from xarray_einstats.stats import mean"}],"quickstart":{"code":"import xarray as xr\nimport numpy as np\nimport xarray_einstats.stats as xestats\n\n# Create a dummy xarray DataArray\ndata = xr.DataArray(\n    np.random.normal(size=(2, 3, 4)),\n    coords={\"a\": [0, 1], \"b\": [0, 1, 2], \"c\": [0, 1, 2, 3]},\n    dims=[\"a\", \"b\", \"c\"],\n)\n\nprint(\"Original data:\\n\", data)\n\n# Calculate the mean along dimension 'b'\nmean_b = xestats.mean(data, dims=\"b\")\nprint(\"\\nMean along 'b' dimension:\\n\", mean_b)\n\n# Use einops-like patterns for more complex operations\n# Reshape 'b c' into a new dimension '(b c)' and then sum\nsum_bc_flattened = xestats.sum(data, dims={\"b c\": \"_\"}) # '_' signifies a new dimension combining 'b' and 'c'\nprint(\"\\nSum after flattening 'b' and 'c' dimensions:\\n\", sum_bc_flattened)","lang":"python","description":"This example demonstrates creating an xarray DataArray and then using `xarray-einstats.stats.mean` to calculate the mean along a specific dimension. It also shows a basic `einops`-like pattern for combining and summing dimensions using a dictionary in the `dims` argument."},"warnings":[{"fix":"Upgrade your Python environment to 3.12 or newer. If you need to use an older Python version (e.g., 3.10 or 3.11), you must pin `xarray-einstats` to a version less than 0.10.0 (e.g., `xarray-einstats<0.10`).","message":"As of version 0.10.0, `xarray-einstats` requires Python 3.12 or newer. This is a significant bump from previous versions (e.g., 0.9.0+ required Python 3.10+).","severity":"breaking","affected_versions":"0.10.0 and above"},{"fix":"Ensure all dependent libraries are updated to their respective minimum versions before upgrading `xarray-einstats` to 0.10.0 or higher. Use `pip install xarray-einstats --upgrade` to let pip handle dependencies or manually update them.","message":"Version 0.10.0 introduced minimum version requirements for key dependencies: `xarray>=2024.2.0`, `scipy>=1.11.0`, `numpy>=1.25.0`, and `einstats>=0.7.0`. Older versions of these libraries are no longer supported.","severity":"breaking","affected_versions":"0.10.0 and above"},{"fix":"Refer to the `einstats` and `xarray-einstats` documentation for detailed examples of `dims` argument usage. Start with simple string or list of strings for basic operations before moving to more complex dictionary patterns for `einops`-like reshaping.","message":"The `dims` argument in `xarray-einstats` functions (e.g., `mean`, `sum`, `quantile`) accepts various formats: a string, a list of strings, or a dictionary for `einops`-like patterns. Misunderstanding the dictionary format, especially for reshaping or combining dimensions, is a common source of errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}