mattiasoldani / succolib

A set of handy, Python-based tools for the INSULAb detectors data analysis
https://github.com/mattiasoldani/succolib
MIT License
0 stars 0 forks source link

add function to rebin histograms #23

Open mattiasoldani opened 2 months ago

mattiasoldani commented 2 months ago

Starting point:

def rebin(x0, y0, nBin):
    x, y = np.empty(0), np.empty(0)
    for i in range(0, math.floor(len(x0)/nBin)*nBin, nBin):
        x = np.append(x, sum(x0[i:(i+nBin)])/nBin)
        y = np.append(y, sum(y0[i:(i+nBin)]))
    return x, y
mattiasoldani commented 2 months ago

Better:

def rebin(x0, y0, nBin):
    x, y = np.empty(0), np.empty(0)
    for i in range(0, int(np.floor(len(x0)/nBin))*nBin, nBin):
        x = np.append(x, sum(x0[i:(i+nBin)])/nBin)
        y = np.append(y, sum(y0[i:(i+nBin)]))
    return x, y