Your little helper to display numpy ndarrays in a pretty table in Jupyter notebooks.

Jupyter notebooks are a great way to develop. ndpretty makes it even better for people who use numpy by providing nice formatting of ndarrays.

Open In Colab

Install

%pip install ndpretty
Requirement already satisfied: ndpretty in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (0.0.3)
Requirement already satisfied: IPython in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from ndpretty) (7.14.0)
Requirement already satisfied: ipywidgets in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from ndpretty) (7.5.1)
Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from ndpretty) (1.18.4)
Requirement already satisfied: pygments in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from IPython->ndpretty) (2.6.1)
Requirement already satisfied: appnope in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from IPython->ndpretty) (0.1.0)
Requirement already satisfied: setuptools>=18.5 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from IPython->ndpretty) (41.2.0)
Requirement already satisfied: pexpect in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from IPython->ndpretty) (4.8.0)
Requirement already satisfied: jedi>=0.10 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from IPython->ndpretty) (0.17.0)
Requirement already satisfied: traitlets>=4.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from IPython->ndpretty) (4.3.3)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from IPython->ndpretty) (3.0.5)
Requirement already satisfied: backcall in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from IPython->ndpretty) (0.1.0)
Requirement already satisfied: decorator in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from IPython->ndpretty) (4.4.2)
Requirement already satisfied: pickleshare in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from IPython->ndpretty) (0.7.5)
Requirement already satisfied: parso>=0.7.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from jedi>=0.10->IPython->ndpretty) (0.7.0)
Requirement already satisfied: wcwidth in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->IPython->ndpretty) (0.1.9)
Requirement already satisfied: six in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from traitlets>=4.2->IPython->ndpretty) (1.15.0)
Requirement already satisfied: ipython-genutils in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from traitlets>=4.2->IPython->ndpretty) (0.2.0)
Requirement already satisfied: nbformat>=4.2.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from ipywidgets->ndpretty) (5.0.6)
Requirement already satisfied: ipykernel>=4.5.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from ipywidgets->ndpretty) (5.3.0)
Requirement already satisfied: widgetsnbextension~=3.5.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from ipywidgets->ndpretty) (3.5.1)
Requirement already satisfied: tornado>=4.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from ipykernel>=4.5.1->ipywidgets->ndpretty) (6.0.4)
Requirement already satisfied: jupyter-client in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from ipykernel>=4.5.1->ipywidgets->ndpretty) (6.1.3)
Requirement already satisfied: jupyter-core in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from nbformat>=4.2.0->ipywidgets->ndpretty) (4.6.3)
Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from nbformat>=4.2.0->ipywidgets->ndpretty) (3.2.0)
Requirement already satisfied: pyrsistent>=0.14.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->ndpretty) (0.16.0)
Requirement already satisfied: attrs>=17.4.0 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->ndpretty) (19.3.0)
Requirement already satisfied: importlib-metadata in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->ndpretty) (1.6.0)
Requirement already satisfied: notebook>=4.4.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (6.0.3)
Requirement already satisfied: pyzmq>=17 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (19.0.1)
Requirement already satisfied: Send2Trash in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (1.5.0)
Requirement already satisfied: prometheus-client in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (0.8.0)
Requirement already satisfied: jinja2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (2.11.2)
Requirement already satisfied: nbconvert in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (5.6.1)
Requirement already satisfied: terminado>=0.8.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (0.8.3)
Requirement already satisfied: python-dateutil>=2.1 in /Users/patrick/Library/Python/3.7/lib/python/site-packages (from jupyter-client->ipykernel>=4.5.1->ipywidgets->ndpretty) (2.8.1)
Requirement already satisfied: ptyprocess in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from terminado>=0.8.1->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (0.6.0)
Requirement already satisfied: zipp>=0.5 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from importlib-metadata->jsonschema!=2.5.0,>=2.4->nbformat>=4.2.0->ipywidgets->ndpretty) (3.1.0)
Requirement already satisfied: MarkupSafe>=0.23 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from jinja2->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (1.1.1)
Requirement already satisfied: bleach in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (3.1.5)
Requirement already satisfied: defusedxml in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (0.6.0)
Requirement already satisfied: testpath in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (0.4.4)
Requirement already satisfied: pandocfilters>=1.4.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (1.4.2)
Requirement already satisfied: mistune<2,>=0.8.1 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (0.8.4)
Requirement already satisfied: entrypoints>=0.2.2 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (0.3)
Requirement already satisfied: packaging in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from bleach->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (20.4)
Requirement already satisfied: webencodings in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from bleach->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (0.5.1)
Requirement already satisfied: pyparsing>=2.0.2 in /Users/patrick/Library/Python/3.7/lib/python/site-packages (from packaging->bleach->nbconvert->notebook>=4.4.1->widgetsnbextension~=3.5.0->ipywidgets->ndpretty) (2.4.6)
Note: you may need to restart the kernel to use updated packages.

How to use

import ndpretty
import numpy as np

Display an ndarray using ndarray_html():

ndpretty.ndarray_html(np.random.rand(3, 4))

If you want all np.ndarrays and torch.Tensors to be automatically formatted like this, load the default configuration:

ndpretty.default()

After this line has been exectued, all cell outputs that are np.ndarray or torch.Tensor are automatically formatted by ndpretty.

a = np.random.rand(10, 5)
a
10×5 float64 ndarray

It works with all numpy dtypes, multi-dimensional arrays and PyTorch tensors.

Find more usage examples here.

Why?

Look at the alternatives.

Author

Patrick Deutschmann (patrick@deutschmann.xyz)