processing_library/util/array_functions.py
def average_chunks_jit(arr, wts, chunksize):
    """ Average the array arr with weights by chunks

    Array len does not have to be multiple of chunksize
    
    This is a version written for numba. When used with numba.jit, it's about 25 - 30% faster than the
    numpy version without jit.
    
    :param arr: 1D array of values
    :param wts: 1D array of weights
    :param chunksize: averaging size
    :return: 1D array of averaged data_models, 1d array of weights
    """
    if chunksize <= 1:
        return arr, wts
    nchunks = len(arr) // chunksize
    extra = len(arr) % chunksize
    if extra > 0:
        fullsize = nchunks + 1
    else:
        fullsize = nchunks
    
    chunks = numpy.empty(fullsize, dtype=arr.dtype)
    weights = numpy.empty(fullsize, dtype=wts.dtype)
    
    for place in range(nchunks):
        chunks[place] = numpy.sum(
            wts[place * chunksize:(place + 1) * chunksize] * arr[place * chunksize:(place + 1) * chunksize])
        weights[place] = numpy.sum(wts[place * chunksize:(place + 1) * chunksize])
    
    if extra > 0:
        chunks[-1] = numpy.sum(wts[(len(arr) - extra):len(arr)] * arr[(len(arr) - extra):len(arr)])
        weights[-1] = numpy.sum(wts[(len(arr) - extra):len(arr)])
    
    chunks[weights > 0.0] = chunks[weights > 0.0] / weights[weights > 0.0]
    
    return chunks, weights
 Average the array arr with weights by chunks

    Array len does not have to be multiple of chunksize
    
    This is a version written for numba. When used with numba.jit, it's about 25 - 30% faster than the
    numpy version without jit.
    
    :param arr: 1D array of values
    :param wts: 1D array of weights
    :param chunksize: averaging size
    :return: 1D array of averaged data_models, 1d array of weights
    
Average the array arr with weights by chunks
Array len does not have to be multiple of chunksize

This is a version written for numba. When used with numba.jit, it's about 25 - 30% faster than the
numpy version without jit.
Average the array arr with weights by chunks Array len does not have to be multiple of chunksize This is a version written for numba . When used with numba . jit it ' s about 25 - 30% faster than the numpy version without jit .
def average_chunks_jit(arr, wts, chunksize):
    if chunksize <= 1:
        return arr, wts
    nchunks = len(arr) // chunksize
    extra = len(arr) % chunksize
    if extra > 0:
        fullsize = nchunks + 1
    else:
        fullsize = nchunks
    chunks = numpy.empty(fullsize, dtype=arr.dtype)
    weights = numpy.empty(fullsize, dtype=wts.dtype)
    for place in range(nchunks):
        chunks[place] = numpy.sum(
            wts[place * chunksize:(place + 1) * chunksize] * arr[place * chunksize:(place + 1) * chunksize])
        weights[place] = numpy.sum(wts[place * chunksize:(place + 1) * chunksize])
    if extra > 0:
        chunks[-1] = numpy.sum(wts[(len(arr) - extra):len(arr)] * arr[(len(arr) - extra):len(arr)])
        weights[-1] = numpy.sum(wts[(len(arr) - extra):len(arr)])
    chunks[weights > 0.0] = chunks[weights > 0.0] / weights[weights > 0.0]
    return chunks, weights
def average_chunks_jit ( arr , wts , chunksize ) : if chunksize <= 1 : return arr , wts nchunks = len ( arr ) // chunksize extra = len ( arr ) % chunksize if extra > 0 : fullsize = nchunks + 1 else : fullsize = nchunks chunks = numpy . empty ( fullsize , dtype = arr . dtype ) weights = numpy . empty ( fullsize , dtype = wts . dtype ) for place in range ( nchunks ) : chunks [ place ] = numpy . sum ( wts [ place * chunksize : ( place + 1 ) * chunksize ] * arr [ place * chunksize : ( place + 1 ) * chunksize ] ) weights [ place ] = numpy . sum ( wts [ place * chunksize : ( place + 1 ) * chunksize ] ) if extra > 0 : chunks [ - 1 ] = numpy . sum ( wts [ ( len ( arr ) - extra ) : len ( arr ) ] * arr [ ( len ( arr ) - extra ) : len ( arr ) ] ) weights [ - 1 ] = numpy . sum ( wts [ ( len ( arr ) - extra ) : len ( arr ) ] ) chunks [ weights > 0.0 ] = chunks [ weights > 0.0 ] / weights [ weights > 0.0 ] return chunks , weights
Average the array arr with weights by chunks
Array len does not have to be multiple of chunksize
Average the array arr with weights by chunks Array len does not have to be multiple of chunksize
""" Average the array arr with weights by chunks

    Array len does not have to be multiple of chunksize
    
    This is a version written for numba. When used with numba.jit, it's about 25 - 30% faster than the
    numpy version without jit.
    
    :param arr: 1D array of values
    :param wts: 1D array of weights
    :param chunksize: averaging size
    :return: 1D array of averaged data_models, 1d array of weights
    """
1D array of averaged data_models, 1d array of weights
1D array of averaged data_models 1d array of weights
arr
1D array of values
1D array of values
wts
1D array of weights
1D array of weights
chunksize
None