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

    Array len does not have to be multiple of chunksize.
    
    :param arr: 2D array of values
    :param wts: 2D array of weights
    :param chunksize: 2-tuple of averaging region e.g. (2,3)
    :return: 2D array of averaged data_models, 2d array of weights
    """
    # Do each axis to determine length
    #    assert arr.shape == wts.shape, "Shapes of arrays must be the same"
    # It is possible that there is a dangling null axis on wts
    wts = wts.reshape(arr.shape)
    
    l0 = len(average_chunks(arr[:, 0], wts[:, 0], chunksize[0])[0])
    l1 = len(average_chunks(arr[0, :], wts[0, :], chunksize[1])[0])
    
    tempchunks = numpy.zeros([arr.shape[0], l1], dtype=arr.dtype)
    tempwt = numpy.zeros([arr.shape[0], l1])
    
    tempchunks *= tempwt
    for i in range(arr.shape[0]):
        result = average_chunks(arr[i, :], wts[i, :], chunksize[1])
        tempchunks[i, :], tempwt[i, :] = result[0].flatten(), result[1].flatten()
    
    chunks = numpy.zeros([l0, l1], dtype=arr.dtype)
    weights = numpy.zeros([l0, l1])
    
    for i in range(l1):
        result = average_chunks(tempchunks[:, i], tempwt[:, i], chunksize[0])
        chunks[:, i], weights[:, i] = result[0].flatten(), result[1].flatten()
    
    return chunks, weights
 Average the two dimensional array arr with weights by chunks

    Array len does not have to be multiple of chunksize.
    
    :param arr: 2D array of values
    :param wts: 2D array of weights
    :param chunksize: 2-tuple of averaging region e.g. (2,3)
    :return: 2D array of averaged data_models, 2d array of weights
    
Average the two dimensional array arr with weights by chunks
Array len does not have to be multiple of chunksize.
Average the two dimensional array arr with weights by chunks Array len does not have to be multiple of chunksize .
def average_chunks2(arr, wts, chunksize):
    wts = wts.reshape(arr.shape)
    l0 = len(average_chunks(arr[:, 0], wts[:, 0], chunksize[0])[0])
    l1 = len(average_chunks(arr[0, :], wts[0, :], chunksize[1])[0])
    tempchunks = numpy.zeros([arr.shape[0], l1], dtype=arr.dtype)
    tempwt = numpy.zeros([arr.shape[0], l1])
    tempchunks *= tempwt
    for i in range(arr.shape[0]):
        result = average_chunks(arr[i, :], wts[i, :], chunksize[1])
        tempchunks[i, :], tempwt[i, :] = result[0].flatten(), result[1].flatten()
    chunks = numpy.zeros([l0, l1], dtype=arr.dtype)
    weights = numpy.zeros([l0, l1])
    for i in range(l1):
        result = average_chunks(tempchunks[:, i], tempwt[:, i], chunksize[0])
        chunks[:, i], weights[:, i] = result[0].flatten(), result[1].flatten()
    return chunks, weights
def average_chunks2 ( arr , wts , chunksize ) : wts = wts . reshape ( arr . shape ) l0 = len ( average_chunks ( arr [ : , 0 ] , wts [ : , 0 ] , chunksize [ 0 ] ) [ 0 ] ) l1 = len ( average_chunks ( arr [ 0 , : ] , wts [ 0 , : ] , chunksize [ 1 ] ) [ 0 ] ) tempchunks = numpy . zeros ( [ arr . shape [ 0 ] , l1 ] , dtype = arr . dtype ) tempwt = numpy . zeros ( [ arr . shape [ 0 ] , l1 ] ) tempchunks *= tempwt for i in range ( arr . shape [ 0 ] ) : result = average_chunks ( arr [ i , : ] , wts [ i , : ] , chunksize [ 1 ] ) tempchunks [ i , : ] , tempwt [ i , : ] = result [ 0 ] . flatten ( ) , result [ 1 ] . flatten ( ) chunks = numpy . zeros ( [ l0 , l1 ] , dtype = arr . dtype ) weights = numpy . zeros ( [ l0 , l1 ] ) for i in range ( l1 ) : result = average_chunks ( tempchunks [ : , i ] , tempwt [ : , i ] , chunksize [ 0 ] ) chunks [ : , i ] , weights [ : , i ] = result [ 0 ] . flatten ( ) , result [ 1 ] . flatten ( ) return chunks , weights
Average the two dimensional array arr with weights by chunks
Array len does not have to be multiple of chunksize.
Average the two dimensional array arr with weights by chunks Array len does not have to be multiple of chunksize .
""" Average the two dimensional array arr with weights by chunks

    Array len does not have to be multiple of chunksize.
    
    :param arr: 2D array of values
    :param wts: 2D array of weights
    :param chunksize: 2-tuple of averaging region e.g. (2,3)
    :return: 2D array of averaged data_models, 2d array of weights
    """ # Do each axis to determine length #    assert arr.shape == wts.shape, "Shapes of arrays must be the same" # It is possible that there is a dangling null axis on wts
2D array of averaged data_models, 2d array of weights
2D array of averaged data_models 2d array of weights
arr
2D array of values
2D array of values
wts
2D array of weights
2D array of weights
chunksize
2-tuple of averaging region e.g. (2,3)
2 - tuple of averaging region e . g . ( 2 3 )