Boost-histogram

1.7.2 · active · verified Sat Apr 11

Boost-histogram is a high-performance Python library providing bindings for the C++14 Boost.Histogram library, designed for fast, multi-dimensional generalized histogramming. It treats histograms as first-class objects, enabling easy filling, manipulation, slicing, and projection. The library is currently at version 1.7.2 and maintains an active release cadence with frequent updates and new features, often driven by the Scikit-HEP project.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a 1D histogram using a regular axis, fill it with random data, and then access its bin counts and axis centers.

import boost_histogram as bh
import numpy as np

# Create a 1D histogram with 10 bins from 0 to 1
hist = bh.Histogram(bh.axis.Regular(10, 0, 1))

# Fill the histogram with data
data = np.random.rand(1000)
hist.fill(data)

# Access histogram values (counts)
counts = hist.view()
print(f"Histogram counts: {counts[:5]}...")

# Access axis centers
centers = hist.axes[0].centers
print(f"Axis centers: {centers[:5]}...")

view raw JSON →