Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

NumPy-style histograms in PyTorch

Project description

NumPy-style histograms in PyTorch

The torchist package implements NumPy's histogram and histogramdd functions in PyTorch with support for non-uniform binning. The package also features implementations of ravel_multi_index, unravel_index and some useful functionals (e.g. KL divergence).


The torchist package is available on PyPI, which means it is installable with pip:

pip install torchist

Alternatively, if you need the latest features, you can install it using

pip install git+

or copy the package directly to your project, with

git clone
cp -R torchist/torchist <path/to/project>/torchist

Getting Started

import torch
import torchist

x = torch.rand(100, 3).cuda()

hist = torchist.histogramdd(x, bins=10, low=0., upp=1.)

print(hist.shape)  # (10, 10, 10)


The implementations of torchist are on par or faster than those of numpy on CPU and benefit greately from CUDA capabilities.

$ python torchist/
np.histogram : 1.2559 s
np.histogramdd : 20.7816 s
np.histogram (non-uniform) : 5.4878 s
np.histogramdd (non-uniform) : 17.3757 s
torchist.histogram : 1.3975 s
torchist.histogramdd : 9.6160 s
torchist.histogram (non-uniform) : 5.0883 s
torchist.histogramdd (non-uniform) : 17.2743 s

torchist.histogram : 0.1363 s
torchist.histogramdd : 0.3754 s
torchist.histogram (non-uniform) : 0.1355 s
torchist.histogramdd (non-uniform) : 0.5137 s

Project details

Download files

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

Files for torchist, version 0.1.5
Filename, size File type Python version Upload date Hashes
Filename, size torchist-0.1.5-py3-none-any.whl (8.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size torchist-0.1.5.tar.gz (7.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page