Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cgarciae/einop
https://github.com/cgarciae/einop
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/cgarciae/einop
- Owner: cgarciae
- License: mit
- Created: 2022-03-07T20:50:27.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-03-08T13:13:40.000Z (over 2 years ago)
- Last Synced: 2024-10-08T18:55:55.538Z (about 1 month ago)
- Language: Python
- Size: 48.8 KB
- Stars: 57
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Einop
_One op to rule them all_
Einop is a very thin wrapper around [einops](https://github.com/arogozhnikov/einops) that combines `rearrange`, `reduce`, and `repeat` into a single `einop` function. This library is a port of [arogozhnikov/einops#91](https://github.com/arogozhnikov/einops/pull/91) by [Miles Cranmer](https://github.com/MilesCranmer) into a separate library, if at some point that PR is merged use `einop` directly from einops instead.
## Installation
```
pip install einop
```
## Usage
```python
import numpy as np
from einop import einopx = np.random.uniform(size=(10, 20))
y = einop(x, "height width -> batch width height", batch=32)assert y.shape == (32, 20, 10)
```#### Rearrange
```python
x = np.random.randn(100, 5, 3)einop(x, 'i j k -> k i j').shape
>>> (3, 100, 5)
```#### Reduction
```python
x = np.random.randn(100, 5, 3)einop(x, 'i j k -> i j', reduction='sum').shape
>>> (100, 5)
```#### Repeat
```python
x = np.random.randn(100, 5, 3)einop(x, 'i j k -> i j k l', l=10).shape
>>> (100, 5, 3, 10)
```