Converting existing numpy histograms into boost-histograms

160 Views Asked by At

I have a lot of numpy (1d) histograms. Each of them was created like this:

bin_height, bin_edges = np.histogram(data)

What is the best way to turn them into boost-histograms?

1

There are 1 best solutions below

2
On BEST ANSWER

This solution was suggested to me by Hans Dembinski:

import boost_histogram as bh
import numpy as np
import matplotlib.pyplot as plt

# generate some randome data
rng = np.random.RandomState(10)
data = rng.normal(size=1000)

#create numpy histogram
bin_height, bin_edges = np.histogram(data)

#turn it into a boost-histogram
bhist = bh.Histogram(bh.axis.Variable(bin_edges))
bhist.view()[:] = bin_height

#plot it
plt.bar(bhist.axes[0].centers, bhist.view(), width=bhist.axes[0].widths);