def rebin_array(arr, maxlen=500):
    """rebin array and reduce its length to maxlen for generating plots
    """
    l = arr.shape
    if l[0] > maxlen:
        arr = arr[:-(l[0]%maxlen)]
        arr = arr.reshape(maxlen, -1, *l[1:])
        arr = arr.mean(1)
    return arr