Skip to main content

rainbow-tensor

Colourful SVG visuals for tensor shapes, indexing, and operations, built for Jupyter notebooks and teaching.

PyPI version Python versions License Documentation

rt.shape(np.arange(8).reshape(2, 2, 2))

Shape (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

Index (0, :, 1)

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 shape and index, covering integers, slices, ellipsis, new axes, boolean masks, and fancy integer arrays
  • Reshaping and moving axes with reshape, transpose, swapaxes, moveaxis, squeeze, and expand_dims
  • Reductions and math with sum, mean, matmul, and einsum
  • Combining with concatenate, stack, broadcast, repeat, and take
rt.sum(np.arange(12).reshape(3, 4), 0)

Sum over axis 0

rt.einsum("ij,jk->ik", np.arange(6).reshape(2, 3), np.arange(12).reshape(3, 4))

Einsum ij and jk to ik

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

rainbow_tensor-1.0.0.tar.gz (59.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rainbow_tensor-1.0.0-py3-none-any.whl (46.5 kB view details)

Uploaded Python 3

File details

Details for the file rainbow_tensor-1.0.0.tar.gz.

File metadata

  • Download URL: rainbow_tensor-1.0.0.tar.gz
  • Upload date:
  • Size: 59.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rainbow_tensor-1.0.0.tar.gz
Algorithm Hash digest
SHA256 88ee76aa22d9cc6dc54b9f6c7e53b606d5d7da66ea455d8f5f0210e6dce574e4
MD5 c315fbd0294f1d5fefaf0388b09ad3a0
BLAKE2b-256 873108608012a1ac257f3336654d78ccd89bd8d07c4c0f8ca3dac05fa9cc01c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for rainbow_tensor-1.0.0.tar.gz:

Publisher: release.yml on Niox1337/rainbow-tensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rainbow_tensor-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: rainbow_tensor-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 46.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rainbow_tensor-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a260dae56c28415b89ba60351e7587f73037d66e230acea0bd6d5ca75d246481
MD5 65c2da76a434a6da6896966648d071f6
BLAKE2b-256 6eceac29ce913b23efc388dcb4dc11a98122f2b4a6006a8ca46ab69fe000bc7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for rainbow_tensor-1.0.0-py3-none-any.whl:

Publisher: release.yml on Niox1337/rainbow-tensor

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page