Returns a 1D array with higher dimensions aggregated using stat fn.

    Arguments:
    arr -- ndarray
    stat -- numpy or numpy.ma function as str to call

def agg_dims(arr, stat):
    """Returns a 1D array with higher dimensions aggregated using stat fn.

    Arguments:
    arr -- ndarray
    stat -- numpy or numpy.ma function as str to call
    """
    axis = None
    if arr.ndim > 2:
        axis = 1
        arr = arr.reshape(arr.shape[0], -1)
    module = np.ma if hasattr(arr, 'mask') else np
    return getattr(module, stat)(arr, axis)