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

    Array len does not have to be multiple of chunksize
    
    This version is optimised for plain numpy. It is roughly ten times faster that average_chunks_jit when used
    without numba jit. It cannot (yet) be used with numba because the add.reduceat is not support in numba
    0.31
    
    :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

    # Original codes
    # places = range(0, len(arr), chunksize)
    # chunks = numpy.add.reduceat(wts * arr, places)
    # weights = numpy.add.reduceat(wts, places)
    # chunks[weights > 0.0] = chunks[weights > 0.0] / weights[weights > 0.0]

    # Codes optimized

    mask = numpy.zeros(((len(arr)-1)//chunksize + 1, arr.shape[0]), dtype=bool)
    for enumerate_id,i in enumerate(range(0, len(arr), chunksize)):
        mask[enumerate_id,i:i+chunksize]=1
    chunks = mask.dot(wts*arr)
    weights = mask.dot(wts)
    # chunks[weights > 0.0] = chunks[weights > 0.0] / weights[weights > 0.0]
    numpy.putmask(chunks, weights>0.0, chunks/weights)

    return chunks, weights
 Average the array arr with weights by chunks

    Array len does not have to be multiple of chunksize
    
    This version is optimised for plain numpy. It is roughly ten times faster that average_chunks_jit when used
    without numba jit. It cannot (yet) be used with numba because the add.reduceat is not support in numba
    0.31
    
    :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 version is optimised for plain numpy. It is roughly ten times faster that average_chunks_jit when used
without numba jit. It cannot (yet) be used with numba because the add.reduceat is not support in numba
0.31
Average the array arr with weights by chunks Array len does not have to be multiple of chunksize This version is optimised for plain numpy . It is roughly ten times faster that average_chunks_jit when used without numba jit . It cannot ( yet ) be used with numba because the add . reduceat is not support in numba 0 . 31
def average_chunks(arr, wts, chunksize):
    if chunksize <= 1:
        return arr, wts
    mask = numpy.zeros(((len(arr)-1)//chunksize + 1, arr.shape[0]), dtype=bool)
    for enumerate_id,i in enumerate(range(0, len(arr), chunksize)):
        mask[enumerate_id,i:i+chunksize]=1
    chunks = mask.dot(wts*arr)
    weights = mask.dot(wts)
    numpy.putmask(chunks, weights>0.0, chunks/weights)
    return chunks, weights
def average_chunks ( arr , wts , chunksize ) : if chunksize <= 1 : return arr , wts mask = numpy . zeros ( ( ( len ( arr ) - 1 ) // chunksize + 1 , arr . shape [ 0 ] ) , dtype = bool ) for enumerate_id , i in enumerate ( range ( 0 , len ( arr ) , chunksize ) ) : mask [ enumerate_id , i : i + chunksize ] = 1 chunks = mask . dot ( wts * arr ) weights = mask . dot ( wts ) numpy . putmask ( chunks , weights > 0.0 , chunks / weights ) 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 version is optimised for plain numpy. It is roughly ten times faster that average_chunks_jit when used
    without numba jit. It cannot (yet) be used with numba because the add.reduceat is not support in numba
    0.31
    
    :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
    """ # Original codes # places = range(0, len(arr), chunksize) # chunks = numpy.add.reduceat(wts * arr, places) # weights = numpy.add.reduceat(wts, places) # chunks[weights > 0.0] = chunks[weights > 0.0] / weights[weights > 0.0] # Codes optimized # chunks[weights > 0.0] = chunks[weights > 0.0] / weights[weights > 0.0]
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