将现有的 numpy 直方图转换为增强直方图
Converting existing numpy histograms into boost-histograms
我有很多numpy (1d) histograms。他们每个人都是这样创建的:
bin_height, bin_edges = np.histogram(data)
将它们变成 boost-histograms 的最佳方法是什么?
这个解决方案是 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);
我有很多numpy (1d) histograms。他们每个人都是这样创建的:
bin_height, bin_edges = np.histogram(data)
将它们变成 boost-histograms 的最佳方法是什么?
这个解决方案是 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);