syrte
3/23/2016 - 1:54 AM

Return mean value of adjacent member of an array. Useful for plotting bin counts.

Return mean value of adjacent member of an array. Useful for plotting bin counts.

def mid(x, base=None):
    '''Return mean value of adjacent member of an array.
    Useful for plotting bin counts.
    '''
    if base is None:
        x = np.asarray(x)
        return  (x[1:] + x[:-1])/2.
    elif base == 'log':
        return np.exp(mid(np.log(x)))
    elif base == 'exp':
        return np.log(mid(np.exp(x)))
    else:
        assert base > 0
        return np.log(mid(base**x))/np.log(base)