<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def merge_arrays(merge_list, names=None, flatten=True, outtype=None):
 """Merges the given arrays into a single array. The arrays must all have the same shape. If one or more of the given arrays has multiple fields, all of the fields will be included as separate fields in the new array. Parameters merge_list : list of arrays The list of arrays to merge. names : {None | sequence of strings} Optional, the names of the fields in the output array. If flatten is True, must be the same length as the total number of fields in merge_list. Otherise, must be the same length as the number of arrays in merge_list. If None provided, and flatten is True, names used will be the same as the name of the fields in the given arrays. If the datatype has no name, or flatten is False, the new field will be `fi` where i is the index of the array in arrays. flatten : bool Make all of the fields in the given arrays separate fields in the new array. Otherwise, each array will be added as a field. If an array has fields, they will be subfields in the output array. Default is True. outtype : {None | class} Cast the new array to the given type. Default is to return a numpy structured array. Returns ------- new array : {numpy.ndarray | outtype} A new array with all of the fields in all of the arrays merged into a single array. """

    # make sure everything in merge_list is an array
    merge_list = _ensure_array_list(merge_list)
    if not all(merge_list[0].shape == arr.shape for arr in merge_list):
        raise ValueError("all of the arrays in merge_list must have the " +
            "same shape")
    if flatten:
        new_dt = combine_fields([arr.dtype for arr in merge_list])
    else:
        new_dt = numpy.dtype([('f%i' %ii, arr.dtype.descr) \
            for ii,arr in enumerate(merge_list)])
    new_arr = merge_list[0].__class__(merge_list[0].shape, dtype=new_dt)
    # ii is a counter to keep track of which fields from the new array
    # go with which arrays in merge list
    ii = 0
    for arr in merge_list:
        if arr.dtype.names is None:
            new_arr[new_dt.names[ii]] = arr
            ii += 1
        else:
            for field in arr.dtype.names:
                new_arr[field] = arr[field]
                ii += 1
    # set the names if desired
    if names is not None:
        new_arr.dtype.names = names
    # ditto the outtype
    if outtype is not None:
        new_arr = new_arr.view(type=outtype)
    return new_arr