Python 将现有numpy直方图转换为boost直方图
我有很多工作要做。它们中的每一个都是这样创建的:Python 将现有numpy直方图转换为boost直方图,python,numpy,boost,boost-histogram,Python,Numpy,Boost,Boost Histogram,我有很多工作要做。它们中的每一个都是这样创建的: bin_height, bin_edges = np.histogram(data) 什么是将其转化为的最佳方法?此解决方案是由以下人员向我提出的: 请注意,如果尚未创建直方图,则bhist=bh.numpy.histogram(数据,histogram=bh.histogram)是更好的解决方案。bhist[:]=bin_height从0.6或0.7开始受支持。 import boost_histogram as bh import num
bin_height, bin_edges = np.histogram(data)
什么是将其转化为的最佳方法?此解决方案是由以下人员向我提出的:
请注意,如果尚未创建直方图,则
bhist=bh.numpy.histogram(数据,histogram=bh.histogram)
是更好的解决方案。bhist[:]=bin_height
从0.6或0.7开始受支持。
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);