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
  • 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. 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())

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.4.0.tar.gz (103.3 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.4.0-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for arrscope-0.4.0.tar.gz
Algorithm Hash digest
SHA256 4157d18093f25f49fb627b4c7cba12fbd3d90b0848609b6d261c5caf1f6ea475
MD5 497043ad004fa4b1c7cf25502b1835b3
BLAKE2b-256 a754609b195033e118f05a40a2a3e6b80965912c997bec75d77e161c75b41e21

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for arrscope-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c890ff9b24898e121a4c79631d8621586505c8efba527245b950d35df7842430
MD5 1a6d68dadbedfc78e2a4bb5ee5243c82
BLAKE2b-256 88b5313ed070ae2178948157d1e54e0b9024b3bd669aaae77a33c3ce2d7ffc85

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