Skip to main content

Beautiful n-dimensional array visualization for Python

Project description

arrscope

Beautiful n-dimensional array visualization for Python — in the terminal and Jupyter.

from arrscope import scope
import numpy as np

scope(np.random.rand(2, 3, 8, 8), axes=['batch', 'heads', 'h', 'w'])
├── [0] (3, 8, 8)
│   ├── [0,0]: 8×8 grid
│   ├── [0,1]: 8×8 grid
│   └── [0,2]: 8×8 grid
└── [1] (3, 8, 8)
    ...
  min=0.001  max=0.999  mean=0.5  std=0.29  zeros=0.0%

Features

  • 1D → 6D+: Tiered visual grammar — lists, grids, trees, collapsed hierarchies
  • Named axes: Attach semantics to dimensions (batch, heads, h, w)
  • Configurable grid: Pick which axes form the leaf 2D matrix
  • Three color modes:
    • dtype — semantic colors by data type (float=blue, int=green, bool=magenta, …)
    • heatmap — diverging colormap (red→light→blue) by value magnitude
    • sparsity — zeros as ·, non-zeros highlighted in bold
  • Stats overlay: min, max, mean, std, zero%, NaN count
  • Head/tail truncation: large dimensions show first/last N slices with
  • Smart precision: auto-detects significant figures for floats
  • Terminal + Jupyter: Rich ANSI output + static HTML/CSS with dark mode
  • Multi-framework: NumPy, PyTorch, TensorFlow, JAX (lazy imports, no hard deps)

Install

pip install arrscope

Only requires numpy + rich. Torch/TF/JAX are optional — pass any array type, it just works.

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 for clarity
scope(
    np.random.rand(2, 8, 32, 32),
    axes=['batch', 'heads', 'h', 'w'],
    grid=['h', 'w'],
    title='Attention heads',
)

# Pick any dims as the leaf grid
scope(data, axes=['a', 'b', 'c', 'd'], grid=['a', 'b'])

Color modes

scope(arr, mode='dtype')        # default — blue floats, green ints, etc.
scope(arr, mode='heatmap')      # diverging colormap by value
scope(arr, mode='sparsity')     # · for zeros, bold for non-zeros

Stats overlay

Stats are shown by default. Hide with:

scope(arr, stats=False)

Shows: min=0.0 max=1.0 mean=0.5 std=0.29 zeros=12.5%

Truncation

scope(np.random.rand(100, 32, 32), max_height=8)

Shows first 4 + last 4 slices with … (92 more) in between.

Custom formatting

scope(arr, fmt='.2f')          # fixed precision
scope(arr, color=False)        # monochrome
scope(arr, style='html')       # force HTML output in terminal

CLI

# Install globally (ships with the library)
pip install arrscope

# Use from anywhere
arrscope 3x4x5
arrscope 2x3x32x32 --axes batch heads h w --grid h w --mode heatmap
arrscope 20x4x5 --max-height 6 --no-stats

Framework support

Pass any array-like — conversion is automatic:

import torch
scope(torch.randn(2, 3, 4))          # PyTorch

import tensorflow as tf
scope(tf.random.uniform((2, 3, 4)))  # TensorFlow

import jax.numpy as jnp
scope(jnp.array([[1, 2], [3, 4]]))  # JAX

API

scope(
    arr,                          # np.ndarray | torch.Tensor | tf.Tensor | jax.Array
    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_width=None,               # int — max characters wide
    max_height=None,              # int — max rows before truncation
    fmt=None,                     # str — format spec like '.4f'
    color=True,                   # bool — enable/disable color
    mode='dtype',                 # 'dtype' | 'heatmap' | 'sparsity'
    stats=True,                   # bool — show min/max/mean/std/zeros
    style='auto',                 # 'auto' | 'terminal' | 'html'
)

Development

git clone https://github.com/vizarray/arrscope
cd arrscope
uv sync
uv run pytest
uv run python main.py          # demo script
uv run jupyter notebook test.ipynb  # notebook demo

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.1.0.tar.gz (100.2 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.1.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for arrscope-0.1.0.tar.gz
Algorithm Hash digest
SHA256 936b35a4eb106a685f4e03e7acc514654fee06030c3f4cc994903a1bb0c90f81
MD5 dbae7126a56a9137c0f4cd6a13f62d71
BLAKE2b-256 f22d666d5c262effb5d1dd0bae3b38a171c5242a31fe014a9d105394af93b2ee

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for arrscope-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8e329321fa88910ea5e7aac3b3f7df181211163fa96e6c3eeb890f7e2a8c7b73
MD5 80304efe9e8a99e94c84753a66e19877
BLAKE2b-256 5eeb8a5e9c991abb612356424ea0dc003b1031920fdfb9956c0b5ffca6304527

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