Rewrite confusing NumPy reshape calls in your ML code as readable einops patterns that explain the transformation.
Use the same tensor rearrangement code across a PyTorch model and a JAX experiment without rewriting it.
Add einops layers directly inside a neural network definition to make dimension transformations explicit and self-documenting.
Einops is a Python library that makes it easier to write and read code that reshapes, transposes, or combines multi-dimensional arrays (called tensors) used in machine learning. In machine learning, data is constantly being sliced, rearranged, and combined across many dimensions, and the standard ways to do this tend to produce code that is hard to follow. Einops offers a text-based notation where you write out the shape transformation you want in a readable pattern, and the library figures out how to perform it. The core idea borrows from a mathematical notation called Einstein summation, where you describe an operation by naming the dimensions explicitly rather than passing a series of numbers and flags. For example, instead of writing a reshape command with magic numbers, you write something like 'batch channels height width -> batch (channels height width)' and the meaning is clear from the pattern itself. The three main functions are rearrange (for reordering and reshaping), reduce (for reducing dimensions by averaging or summing), and repeat (for expanding a tensor along a new axis). The library works with the major Python array frameworks: NumPy, PyTorch, JAX, TensorFlow, Paddle, MLX, tinygrad, and others. This means the same einops notation works regardless of which underlying framework a project uses. It also provides layer objects so you can slot these operations directly into a neural network model definition. Installation is a single pip command. The project ships four tutorial notebooks covering basics, deep learning use cases, packing and unpacking multiple arrays, and PyTorch-specific examples. A companion website hosts documentation and testimonials, and the project has been adopted in over 10,000 other GitHub repositories. A related paper was accepted at ICLR 2022 and received an oral presentation, which is a competitive distinction in the machine learning research community. The project is actively maintained with recent updates adding new framework backends and compatibility with PyTorch's compilation tools.
← arogozhnikov on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.