'Compute mean of a dataset. A limit can be specified for faster
computation, considering only \'limit\' first elements.'

def _compute_global_mean(self, dataset, session, limit=None):

    _dataset = dataset
    mean = 0.0
    if isinstance(limit, int):
        _dataset = _dataset[:limit]
    if (isinstance(_dataset, np.ndarray) and (not self.global_mean_pc)):
        mean = np.mean(_dataset)
    else:
        for i in range(len(dataset)):
            if (not self.global_mean_pc):
                mean += (np.mean(dataset[i]) / len(dataset))
            else:
                mean += (np.mean(dataset[i], axis=(0, 1), keepdims=True) / len(dataset))[0][0]
    self.global_mean.assign(mean, session)
    return mean
