<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def mode(data, channels=None):
 """ Calculate the mode of the events in an FCSData object. Parameters data : FCSData or numpy array NxD flow cytometry data where N is the number of events and D is the number of parameters (aka channels). channels : int or str or list of int or list of str, optional Channels on which to calculate the statistic. If None, use all channels. Returns ------- float or numpy array The mode of the events in the specified channels of `data`. """

    # Slice data to take statistics from
    if channels is None:
        data_stats = data
    else:
        data_stats = data[:, channels]

    # Calculate and return statistic
    # scipy.stats.mode returns two outputs, the first of which is an array
    # containing the modal values. This array has the same number of
    # dimensions as the input, and with only one element in the first
    # dimension. We extract this fist element to make it match the other
    # functions in this module.
    return scipy.stats.mode(data_stats, axis=0)[0][0]