在直方图中重新装箱计数 (Python)

Re-binning counts in a histogram (Python)

提问人:cr_007 提问时间:9/7/2023 最后编辑:cr_007 更新时间:9/7/2023 访问量:33

问:

我在 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
Python 统计 物理 分箱

评论

0赞 Jesse Sealand 9/7/2023
我不听从你的要求。似乎你随机地将“一些东西”放入不同的组中?数据是什么样子的,你能澄清一下你说的reb-bin是什么意思吗?
0赞 AJ Biffl 9/7/2023
确切地知道 和 中包含的内容会很有帮助 - 这些是直方图计数吗?这些是飞行时间的数组吗?如果您正在处理 tof 数组,则没有关于 bin 的“re” - 只需使用您想要的任何 bin 调用 np.histogram 即可tof_n22tof_n30
0赞 cr_007 9/7/2023
我理解。让我想出一个更好的方法来表述我的问题。同时,如果有人有飞行时间数据分析经验并理解我想说的话,请插话。

答: 暂无答案