<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(keys, axis=semantics.axis_default, weights=None, return_indices=False):
 """compute the mode, or most frequent occuring key in a set Parameters input array. elements of 'keys' can have arbitrary shape or dtype weights : ndarray, [n_keys], optional if given, the contribution of each key to the mode is weighted by the given weights return_indices : bool if True, return all indices such that keys[indices]==mode holds Returns ------- the most frequently occuring key in the key sequence indices : ndarray, [mode_multiplicity], int, optional if return_indices is True, all indices such that points[indices]==mode holds """

    index = as_index(keys, axis)
    if weights is None:
        unique, weights = count(index)
    else:
        unique, weights = group_by(index).sum(weights)
    bin = np.argmax(weights)
    _mode = unique[bin]     # FIXME: replace with index.take for lexindex compatibility?
    if return_indices:
        indices = index.sorter[index.start[bin]: index.stop[bin]]
        return _mode, indices
    else:
        return _mode