def average_arrays ( arrays : List [ mx . nd . NDArray ] ) -> mx . nd . NDArray : if not arrays : raise ValueError ( "arrays is empty." ) if len ( arrays ) == 1 : return arrays [ 0 ] check_condition ( all ( arrays [ 0 ] . shape == a . shape for a in arrays ) , "nd array shapes do not match" ) return mx . nd . add_n ( * arrays ) / len ( arrays )
average multiple 2d arrays python
Take a list of arrays of the same shape and take the element wise average .
def average_arrays(arrays: List[mx.nd.NDArray]) -> mx.nd.NDArray:
    """
    Take a list of arrays of the same shape and take the element wise average.

    :param arrays: A list of NDArrays with the same shape that will be averaged.
    :return: The average of the NDArrays in the same context as arrays[0].
    """
    if not arrays:
        raise ValueError("arrays is empty.")
    if len(arrays) == 1:
        return arrays[0]
    check_condition(all(arrays[0].shape == a.shape for a in arrays), "nd array shapes do not match")
    return mx.nd.add_n(*arrays) / len(arrays)