rainbow-tensor
Colourful SVG visuals for tensor shapes, indexing, and operations, built for Jupyter notebooks and teaching.
rt.shape(np.arange(8).reshape(2, 2, 2))
Why rainbow-tensor
Tensor shapes are hard to hold in your head, and an index like (0, slice(None), 1) gives no hint of what it selects until you run it. A printed array is just a wall of numbers. rainbow-tensor draws the tensor as nested coloured frames and highlights exactly which elements an operation touches, so the structure and the result are clear at a glance.
Every axis keeps one colour through every view, so you can follow an axis as it moves, folds, or stretches. That makes it a fast way to learn how reshapes and reductions work, to teach shape transformations, and to debug a confusing indexing or broadcasting bug. The core imports no deep learning framework, so it stays light and works with plain NumPy or any array that exposes a shape.
Install
pip install rainbow-tensor
The distribution name is rainbow-tensor and the import name is rainbow_tensor.
Quick start
Run inside a Jupyter notebook or an IPython shell so the SVG is displayed. The convention is to import the package as rt.
import numpy as np
import rainbow_tensor as rt
x = np.arange(8).reshape(2, 2, 2)
rt.shape(x) # draw the structure
rt.index(x, (0, slice(None), 1)) # highlight what an index selects
Each call returns a small result object. Its svg attribute holds the SVG string, its text attribute holds the explanation printed under the figure, and save writes the SVG to a file.
What it can show
Shape changing, combining, and broadcasting views draw the source and the result side by side, so the mapping between them is easy to follow.
- Shapes and indexing with
shapeandindex, covering integers, slices, ellipsis, new axes, boolean masks, and fancy integer arrays - Reshaping and moving axes with
reshape,transpose,swapaxes,moveaxis,squeeze, andexpand_dims - Reductions and math with
sum,mean,matmul, andeinsum - Combining with
concatenate,stack,broadcast,repeat, andtake
rt.sum(np.arange(12).reshape(3, 4), 0)
rt.einsum("ij,jk->ik", np.arange(6).reshape(2, 3), np.arange(12).reshape(3, 4))
Themes
Pass theme="dark" to any call, or set a module default that every later call follows. A theme is a plain object you can tweak with variant, and a global axis ramp can be set once with set_default_axis_colors.
rt.shape(x, theme="dark")
rt.set_default_theme("dark")
Documentation
The full guide and API reference live at rainbow-tensor.zhixiangfeng.com.
Runnable notebooks for every feature group live in examples, and more sample images live in examples/images.
Development
pip install -e ".[dev]"
pytest
ruff check .
python -m build
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rainbow_tensor-1.0.1.tar.gz.
File metadata
- Download URL: rainbow_tensor-1.0.1.tar.gz
- Upload date:
- Size: 61.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ab26f752ed2edae0f2b6853201785b37d63a1beb586de36a64b17e423d12be7
|
|
| MD5 |
e36cfa419bebc4703590fd846e0ba14f
|
|
| BLAKE2b-256 |
01f7437414f4184af4b9c9d2d61222cc70ded098d6b0837fefed7fb41ddc6b84
|
Provenance
The following attestation bundles were made for rainbow_tensor-1.0.1.tar.gz:
Publisher:
release.yml on Niox1337/rainbow-tensor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rainbow_tensor-1.0.1.tar.gz -
Subject digest:
5ab26f752ed2edae0f2b6853201785b37d63a1beb586de36a64b17e423d12be7 - Sigstore transparency entry: 1907875371
- Sigstore integration time:
-
Permalink:
Niox1337/rainbow-tensor@92bbd9eb961587beabc5d58644dda2064102ef1c -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Niox1337
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@92bbd9eb961587beabc5d58644dda2064102ef1c -
Trigger Event:
push
-
Statement type:
File details
Details for the file rainbow_tensor-1.0.1-py3-none-any.whl.
File metadata
- Download URL: rainbow_tensor-1.0.1-py3-none-any.whl
- Upload date:
- Size: 52.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af8b2ff1862cbdb4f04d04574d756667fbdca3c25e73f30011ad2d61e82f9895
|
|
| MD5 |
9f723bf3f204cc013d0e268180933de8
|
|
| BLAKE2b-256 |
8d6db98643bc8fe4669cdbc02ac5e05f7cfb0cbf287688ef506c0ee15adced96
|
Provenance
The following attestation bundles were made for rainbow_tensor-1.0.1-py3-none-any.whl:
Publisher:
release.yml on Niox1337/rainbow-tensor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rainbow_tensor-1.0.1-py3-none-any.whl -
Subject digest:
af8b2ff1862cbdb4f04d04574d756667fbdca3c25e73f30011ad2d61e82f9895 - Sigstore transparency entry: 1907875425
- Sigstore integration time:
-
Permalink:
Niox1337/rainbow-tensor@92bbd9eb961587beabc5d58644dda2064102ef1c -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/Niox1337
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@92bbd9eb961587beabc5d58644dda2064102ef1c -
Trigger Event:
push
-
Statement type: