def rebin_matrix(arr, N=2):
    """Rebin array by factor of N (not necessarily multiple of 2)"""
    d, r = divmod(len(arr), N)
    if r:
        d += 1
    return [sum(arr[N * i:N * i + N]) / float(N) for i in range(d)]