提问人:cr_007 提问时间:9/7/2023 最后编辑:cr_007 更新时间:9/7/2023 访问量:33
在直方图中重新装箱计数 (Python)
Re-binning counts in a histogram (Python)
问:
我在 Python 中使用两个数据集(tof_n22 和 tof_n30),我需要重新装箱数据并将其绘制为另一个直方图。这两个数据集是中子飞行时间数据,我正在尝试根据测量的中子能量重新装箱这些数据。我遇到了一种随机化方法,在该方法中,您可以通过 bin 宽度 * 0 到 1 之间的随机数更新直方图中的每个事件。我这样做了 N 次,然后绘制了新的直方图。这是使用随机化重新装箱数据的正确方法吗?我附上了下面的示例代码:
bin_width22 = (max(tof_n22) - min(tof_n22))/num_bins #calculate bin widths in datasets
bin_width30 = (max(tof_n30) - min(tof_n30))/num_bins
N = 100
# creating copies of the two datasets
tof_n22_new = tof_n22.copy()
tof_n30_new = tof_n30.copy()
for i in range(0,N):
# generate uniform random number arrays
rnd_22 = np.random.uniform(0,1,len(tof_n22))
rnd_30 = np.random.uniform(0,1,len(tof_n30))
# update the copy datasets by bin width*random number
tof_n22_new += bin_width22*rnd_22
tof_n30_new += bin_width30*rnd_30
# add the old values to the updated values
tof_n22_new += tof_n22
tof_n30_new += tof_n30
# average of all the runs
tof_n22_avg = tof_n22_new/N
tof_n30_avg = tof_n30_new/N
答: 暂无答案
评论
np.histogram
即可tof_n22
tof_n30