<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def mean(self, values, axis=0, weights=None, dtype=None):
 """compute the mean over each group Parameters values to take average of per group axis : int, optional alternative reduction axis for values weight to use for each value dtype : output dtype Returns ------- unique: ndarray, [groups] unique keys value array, reduced over groups """

        values = np.asarray(values)
        if weights is None:
            result = self.reduce(values, axis=axis, dtype=dtype)
            shape = [1] * values.ndim
            shape[axis] = self.groups
            weights = self.count.reshape(shape)
        else:
            weights = np.asarray(weights)
            result = self.reduce(values * weights, axis=axis, dtype=dtype)
            weights = self.reduce(weights, axis=axis, dtype=dtype)
        return self.unique, result / weights