Skip to main content

Beautiful n-dimensional array visualization for Python

Project description

arrscope

Visualize n-dimensional arrays in the terminal and Jupyter — with structural trees, tiled mosaics, array diffing, and distribution sparklines.

from arrscope import scope
import numpy as np

scope(np.random.rand(3, 4, 5))

Features

  • 1D → 6D+: Tiered visual grammar — lists, grids, trees, nested layers
  • Named axes: Attach semantics (batch, heads, h, w)
  • Four color modes:
    • dtype — semantic colors by data type (blue=float, green=int, …)
    • heatmap — diverging colormap (red → light → blue) by value
    • sparsity — zeros as ·, non-zeros in bold
    • diff — compare with a reference array (red=increased, blue=decreased, grey=unchanged)
  • Two render styles:
    • tree (default) — hierarchical branch view with colored guide lines
    • mosaic — all 2D sub-slices tiled side by side as numeric tables
  • Distribution sparkline: every output shows a unicode histogram (▁▂▃▄▅▆▇█) of value distribution — replaces text stats
  • Source-expression labels: like icecream's ic(), scope(np.ones((4, 5))) auto-labels the output with np.ones((4, 5)) when you don't pass title=
  • Array diffing: pass reference= to compare any two arrays. Color-coded per-cell changes + aggregate metrics (MSE, % changed)
  • Head/tail truncation: large dims show first/last N slices with (default 20)
  • Smart precision: auto-detects significant figures for floats
  • Terminal + Jupyter: Rich ANSI + static HTML/CSS with dark mode auto-detect
  • Multi-framework: NumPy, PyTorch, TensorFlow, JAX, tinygrad (lazy imports)
  • Zero config: color always on, stats always on, auto-detect terminal vs notebook

Install

pip install arrscope

Only requires numpy + rich + executing. Torch/TF/JAX/tinygrad are optional.

Quick start

from arrscope import scope
import numpy as np

# Auto-detect — last 2 dims form the grid
scope(np.random.rand(3, 4, 5))

# Named axes
scope(
    np.random.rand(2, 8, 32, 32),
    axes=['batch', 'heads', 'h', 'w'],
    grid=['h', 'w'],
    title='Attention heads',
)

# Custom grid dims
scope(data, axes=['a', 'b', 'c', 'd'], grid=['a', 'b'])

# Method chaining
r = scope(arr, mode='heatmap')
print(r.tree())
print(r.mosaic())

Source-expression labels

When you don't pass title=, arrscope inspects the call site and labels the output with the expression you passed in — the same trick icecream.ic() uses:

scope(np.ones((4, 5, 6, 3)))   # labeled "np.ones((4, 5, 6, 3))"
scope(weights)                  # labeled "weights"
scope(x, title="Custom")        # explicit title always wins

Falls back to no label (never raises) when the source isn't available, e.g. in a plain REPL or python -c.

Color modes

scope(arr, mode='dtype')          # default — blue floats, green ints, ...
scope(arr, mode='heatmap')        # diverging colormap by value
scope(arr, mode='sparsity')       # · for zeros, bold for non-zeros
scope(arr, mode='diff',           # red/blue by change direction
      reference=original_array)   # Δ -0.5  ▁▂▃▄▅▆▇█  +0.5  mse=0.02  12% changed

Array diffing

Compare any two arrays of the same shape. Values show the current array; color encodes the change:

before = np.random.rand(3, 4, 5)
after  = before + np.random.normal(0, 0.1, before.shape)

scope(after, reference=before, mode="diff")

Diff stats replace the sparkline: range of deltas, MSE, and percentage of elements that changed.

Render styles

scope(arr)                        # tree (default) — click-to-expand layers
scope(arr, render_style='mosaic') # all sub-slices tiled side by side

CLI

arrscope 3x4x5
arrscope 2x3x32x32 --axes batch heads h w --grid h w --mode heatmap
arrscope 20x4x5 --max-height 6

Framework support

import torch; scope(torch.randn(2, 3, 4))
import tensorflow as tf; scope(tf.random.uniform((2, 3, 4)))
import jax.numpy as jnp; scope(jnp.array([[1, 2], [3, 4]]))
from tinygrad import Tensor; scope(Tensor.randn(3, 4))

API

scope(
    arr,
    axes=None,            # list[str] — name each dimension
    grid=None,            # list[str | int] — which dims form the leaf grid
    title=None,           # str — heading above the visualization
    max_height=20,        # int | None — rows before truncation, None disables
    fmt=None,             # str — format spec like '.4f'
    mode='dtype',         # 'dtype' | 'heatmap' | 'sparsity' | 'diff'
    render_style='tree',  # 'tree' | 'mosaic'
    reference=None,       # array-like — reference for diff mode
)

Development

git clone https://github.com/vizarray/arrscope
cd arrscope
uv sync
uv run pytest
uv run python main.py

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arrscope-0.5.0.tar.gz (104.4 kB view details)

Uploaded Source

Built Distribution

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

arrscope-0.5.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file arrscope-0.5.0.tar.gz.

File metadata

  • Download URL: arrscope-0.5.0.tar.gz
  • Upload date:
  • Size: 104.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.9

File hashes

Hashes for arrscope-0.5.0.tar.gz
Algorithm Hash digest
SHA256 8d3e2f35f07b8c45c905f9392b1ff6726eb5c72c771fc7e85c7022a5d047f739
MD5 ab21dd50b2385ab263ffe92ff22dafa1
BLAKE2b-256 4ab268e89298558c9d807cff400912c1f31bd7c28f92d40e83c295841b8fb09e

See more details on using hashes here.

File details

Details for the file arrscope-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: arrscope-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.9

File hashes

Hashes for arrscope-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d340288d78d1edba78d740ae2786650a71c8f042b5f6e84dd86fdcfa87453252
MD5 eb7afa6feee43b67ac5c83775dfd205f
BLAKE2b-256 a706b5e4dbac952d42afc0ceae0a5a7ff7c62e898200006faca1236f024ec34c

See more details on using hashes here.

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