Install & Compatibility
Where this runs
tested against v0.8.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.018s · 18.3MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.016s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
rearrange
✓ from einops import rearrange
reduce
✓ from einops import reduce
repeat
✓ from einops import repeat
einsum
✓ from einops import einsum
pack
✓ from einops import pack
unpack
✓ from einops import unpack
EinMix
✓ from einops.layers.torch import EinMix
Import path for layers depends on the specific deep learning framework (e.g., `einops.layers.tf`, `einops.layers.jax`).
This quickstart demonstrates the core `rearrange` operation using NumPy. It shows how to combine dimensions (e.g., batch and height) and flatten dimensions (e.g., width and channel) using a concise, readable pattern string.
import numpy as np
from einops import rearrange
# Suppose we have a batch of 6 images, each 96x96 with 3 color channels
images = np.random.randn(6, 96, 96, 3)
print(f"Original shape: {images.shape}")
# Rearrange to stack images vertically (batch and height become one dimension)
stacked_images = rearrange(images, 'b h w c -> (b h) w c')
print(f"Stacked shape: {stacked_images.shape}")
# Alternatively, flatten width and channel for a 2D representation
flattened_data = rearrange(images, 'b h w c -> b h (w c)')
print(f"Flattened shape: {flattened_data.shape}")
Debug
Known issues
breakingTensorFlow layers in `einops` were updated in v0.8.0 to align with TF 2.16+ and are no longer compatible with older TensorFlow versions (e.g., TF 2.13).fixUpgrade TensorFlow to 2.16 or newer, or stick to `einops < 0.8.0` for older TensorFlow versions.
affects: >=0.8.0
breakingSupport for Python 3.7 was officially dropped in `einops` v0.7.0. The minimum required Python version is now 3.9.fixUpgrade your Python environment to 3.9 or newer.
affects: >=0.7.0
breakingAs of v0.8.2, the minimum required Python version for `einops` is Python 3.9.fixEnsure your Python environment is 3.9 or newer before upgrading to `einops >= 0.8.2`.
affects: >=0.8.2
deprecatedSupport for the Gluon (MXNet) backend was dropped in v0.6.1 and confirmed removed in v0.7.0. Operations with MXNet tensors are no longer supported directly by `einops`.fixMigrate to a supported backend like PyTorch, TensorFlow, JAX, or NumPy.
affects: >=0.6.1
gotchaThe integration with `torch.compile` has evolved across versions. In `einops < 0.7.0`, explicit registration via `einops._torch_specific.allow_ops_in_compiled_graph()` was required. From `v0.7.0` onwards, `torch.compile` integration became largely automatic. With `einops >= 0.8.2` and `torch >= 2.8`, `torch.compile` natively handles `einops` operations without any specific `einops` hints or registrations.fixFor `einops < 0.7.0`, ensure `einops._torch_specific.allow_ops_in_compiled_graph()` is called. For `einops >= 0.7.0`, no explicit action is usually needed, but ensure your PyTorch version is recent enough (especially `torch >= 2.8` for `einops >= 0.8.2`) to benefit from the latest native compilation.
affects: All versions using `torch.compile` (>=0.6.1)
gotchaEllipsis (`...`) support was added to `EinMix` layers in v0.8.1, allowing for more flexible input patterns in mixed-precision operations.fixUpgrade to `einops >= 0.8.1` to utilize ellipsis in `EinMix` patterns.
affects: <0.8.1
breakingThe test environment is missing the `numpy` package, which is a required dependency for using `einops` with the NumPy backend. This prevents the script from executing.fixEnsure `numpy` is installed in your Python environment (e.g., `pip install numpy`).
affects: All versions that utilize the NumPy backend.
gotchaUsing `einops` with NumPy arrays requires `numpy` to be explicitly installed in your environment. While `einops` supports multiple backends, `numpy` is a common prerequisite for many usage patterns and examples.fixEnsure `numpy` is installed in your environment using `pip install numpy`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'einops'
The 'einops' library is not installed in the Python environment you are currently using, or there's an issue with your Python environment's path.
fixInstall the 'einops' library using pip: `pip install einops` or, if using a specific Python interpreter, `python -m pip install einops`.
EinopsError: Error while processing rearrange-reduction pattern "..." Input tensor shape: ... Additional info: ... Shape mismatch, X != Y.
The dimensions specified in the `einops` pattern do not match the actual shape of the input tensor. This often happens when composite dimensions (e.g., `(b1 b2)`) don't multiply to the corresponding input dimension size, or named dimensions provided in `**axes_lengths` don't align.
fixReview your `einops` pattern and the actual shape of your input tensor. Ensure that all decomposed dimensions in parentheses (e.g., `(h w)`) correctly multiply to the size of the corresponding dimension in the input tensor, and that any explicitly provided `axes_lengths` match the tensor's dimensions.
EinopsError: Undefined axis name '...' for rearrange/reduce/repeat
You have used an axis name in your `einops` pattern (e.g., `rearrange(tensor, 'b h w c -> (b x) h w c')`) that is not present in the input tensor and has not been provided as an explicit length argument (e.g., `x=2`).
fixEnsure all axis names used in the pattern are either derived from the input tensor's dimensions or explicitly defined with their lengths as keyword arguments to the `rearrange`, `reduce`, or `repeat` function.
einops.layers.torch.Rearrange does not accept a list[torch.Tensor] as an input
The `einops.layers.torch.Rearrange` layer expects a single tensor as input, but it received a list of tensors, which it cannot directly process for concatenation or other operations that `einops.rearrange` can handle when given multiple inputs.
fixIf you intend to concatenate multiple tensors, use the functional `einops.rearrange` directly with a list of tensors, or concatenate the tensors using `torch.cat` (or equivalent) *before* passing a single resulting tensor to `einops.layers.torch.Rearrange`.
Upgrade
Version history
0.8.2latest on PyPI · released Jan 26, 2026
Audit
Dependencies
torchoptionalCommonly used backend for deep learning operations.
tensorflowoptionalCommonly used backend for deep learning operations.
jaxoptionalCommonly used backend for deep learning operations.
numpyoptionalUniversal array manipulation backend.