{"id":860,"library":"einops","title":"Einops: A New Flavor of Deep Learning Operations","description":"Einops (Einstein operations) is a Python library that provides a flexible and powerful way to reshape and manipulate tensors in deep learning frameworks like PyTorch, TensorFlow, JAX, and NumPy. It simplifies complex tensor operations using a human-readable notation, often replacing verbose permutations, transpositions, and reshaping operations. The library is actively maintained with frequent releases, currently at version 0.8.2.","status":"active","version":"0.8.2","language":"python","source_language":"en","source_url":"https://github.com/arogozhnikov/einops","tags":["deep learning","tensor manipulation","array operations","einsum","pytorch","tensorflow","jax","numpy","machine learning"],"install":[{"cmd":"pip install einops","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Commonly used backend for deep learning operations.","package":"torch","optional":true},{"reason":"Commonly used backend for deep learning operations.","package":"tensorflow","optional":true},{"reason":"Commonly used backend for deep learning operations.","package":"jax","optional":true},{"reason":"Universal array manipulation backend.","package":"numpy","optional":true}],"imports":[{"symbol":"rearrange","correct":"from einops import rearrange"},{"symbol":"reduce","correct":"from einops import reduce"},{"symbol":"repeat","correct":"from einops import repeat"},{"symbol":"einsum","correct":"from einops import einsum"},{"symbol":"pack","correct":"from einops import pack"},{"symbol":"unpack","correct":"from einops import unpack"},{"note":"Import path for layers depends on the specific deep learning framework (e.g., `einops.layers.tf`, `einops.layers.jax`).","symbol":"EinMix","correct":"from einops.layers.torch import EinMix"}],"quickstart":{"code":"import numpy as np\nfrom einops import rearrange\n\n# Suppose we have a batch of 6 images, each 96x96 with 3 color channels\nimages = np.random.randn(6, 96, 96, 3)\nprint(f\"Original shape: {images.shape}\")\n\n# Rearrange to stack images vertically (batch and height become one dimension)\nstacked_images = rearrange(images, 'b h w c -> (b h) w c')\nprint(f\"Stacked shape: {stacked_images.shape}\")\n\n# Alternatively, flatten width and channel for a 2D representation\nflattened_data = rearrange(images, 'b h w c -> b h (w c)')\nprint(f\"Flattened shape: {flattened_data.shape}\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade TensorFlow to 2.16 or newer, or stick to `einops < 0.8.0` for older TensorFlow versions.","message":"TensorFlow 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).","severity":"breaking","affected_versions":">=0.8.0"},{"fix":"Upgrade your Python environment to 3.9 or newer.","message":"Support for Python 3.7 was officially dropped in `einops` v0.7.0. The minimum required Python version is now 3.9.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Ensure your Python environment is 3.9 or newer before upgrading to `einops >= 0.8.2`.","message":"As of v0.8.2, the minimum required Python version for `einops` is Python 3.9.","severity":"breaking","affected_versions":">=0.8.2"},{"fix":"Migrate to a supported backend like PyTorch, TensorFlow, JAX, or NumPy.","message":"Support 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`.","severity":"deprecated","affected_versions":">=0.6.1"},{"fix":"For `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.","message":"The 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.","severity":"gotcha","affected_versions":"All versions using `torch.compile` (>=0.6.1)"},{"fix":"Upgrade to `einops >= 0.8.1` to utilize ellipsis in `EinMix` patterns.","message":"Ellipsis (`...`) support was added to `EinMix` layers in v0.8.1, allowing for more flexible input patterns in mixed-precision operations.","severity":"gotcha","affected_versions":"<0.8.1"},{"fix":"Ensure `numpy` is installed in your Python environment (e.g., `pip install numpy`).","message":"The 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.","severity":"breaking","affected_versions":"All versions that utilize the NumPy backend."},{"fix":"Ensure `numpy` is installed in your environment using `pip install numpy`.","message":"Using `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T20:30:23.450Z","next_check":"2026-06-27T00:00:00.000Z","problems":[{"fix":"Install the 'einops' library using pip: `pip install einops` or, if using a specific Python interpreter, `python -m pip install einops`.","cause":"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.","error":"ModuleNotFoundError: No module named 'einops'"},{"fix":"Review 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.","cause":"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.","error":"EinopsError: Error while processing rearrange-reduction pattern \"...\" Input tensor shape: ... Additional info: ... Shape mismatch, X != Y."},{"fix":"Ensure 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.","cause":"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`).","error":"EinopsError: Undefined axis name '...' for rearrange/reduce/repeat"},{"fix":"If 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`.","cause":"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.","error":"einops.layers.torch.Rearrange does not accept a list[torch.Tensor] as an input"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.8.2","cli_name":"","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.7,"disk_size":"18.3M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.7,"disk_size":"18.3M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.6,"import_time_s":0.01,"mem_mb":0.7,"disk_size":"19M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.7,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"20.3M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.1,"disk_size":"20.3M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.6,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"21M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.9,"disk_size":"12.1M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.9,"disk_size":"12.1M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.5,"import_time_s":0.02,"mem_mb":0.9,"disk_size":"13M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.9,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1,"disk_size":"11.8M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1,"disk_size":"11.7M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.5,"import_time_s":0.02,"mem_mb":0.8,"disk_size":"12M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.8,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.7,"disk_size":"17.8M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.7,"disk_size":"17.8M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.8,"import_time_s":0.01,"mem_mb":0.7,"disk_size":"18M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":0.7,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":null,"tag_description":null,"results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}}