<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 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)