1

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?

Jim Pivarski
  • 5,568
  • 2
  • 35
  • 47
muzzle
  • 315
  • 3
  • 9

1 Answers1

1

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);
muzzle
  • 315
  • 3
  • 9