fast-histogram
raw JSON → 0.14 verified Fri May 01 auth: no python
Fast simple 1D and 2D histograms for Python, using C extensions. Current version: 0.14, released 2024-08-12. Cadence: irregular.
pip install fast-histogram Common errors
error ModuleNotFoundError: No module named 'fast_histogram' ↓
cause Trying to import from 'fast_histogram' but installed package is 'fast-histogram'.
fix
Install correctly: pip install fast-histogram. Then import: from fast_histogram import histogram1d
error ValueError: The 'range' argument is required ↓
cause range not provided or set to None.
fix
Always provide a range tuple, e.g., histogram1d(data, bins=50, range=(-3, 3))
Warnings
breaking v0.13 dropped support for Python <=3.8 and requires numpy >= 1.20, v0.14 requires Python >=3.9 and numpy >= 1.22 to support numpy 2.0. ↓
fix Upgrade to v0.14 and ensure Python 3.9+ and numpy >=1.22.
gotcha The range argument must be provided explicitly; it defaults to None which raises an error. ↓
fix Always specify range as a tuple (min, max) or (xmin, xmax, ymin, ymax) for 2D.
deprecated The numpy.histogram and numpy.histogram2d are slower; this library is intended as a drop-in replacement but weights behavior differs slightly. ↓
fix Check that weights are handled identically; fast-histogram does not support normed/density directly.
Imports
- histogram1d wrong
from fasthistogram import histogram1dcorrectfrom fast_histogram import histogram1d - histogram2d wrong
from fast_histogram import histogram2dcorrectfrom fast_histogram import histogram2d
Quickstart
import numpy as np
from fast_histogram import histogram1d
data = np.random.randn(1000)
bins = 50
range_vals = (-3, 3)
h = histogram1d(data, bins=bins, range=range_vals)
print(h.shape)