Exemplo n.º 1
0
def reduce_mean(input_tensor,
                axis=None,
                keep_dims=False,
                name=None,
                reduction_indices=None):

    if reduction_indices is not None:
        if axis is not None:
            raise ValueError(
                "cannot specify both 'axis' and 'reduction_indices'.")
        axis = reduction_indices
    elif axis is None:
        axis = -1  # reduce all
    if isinstance(axis, list) or isinstance(axis,
                                            tuple):  # reduce continuously
        if len(axis) < 1:
            raise RuntimeError('reduce axes should at least have one.')
        if len(axis) == 1:
            return ops.Mean(input_tensor, axis=axis[0], keep_dims=keep_dims)
        else:
            ret = ops.Mean(input_tensor, axis=axis[0], keep_dims=True)
            for i in xrange(1, len(axis) - 1):
                ret = ops.Mean(ret, axis=axis[i], keep_dims=True)
            return ops.Mean(ret, axis=axis[len(axis) - 1], keep_dims=keep_dims)
    else:
        return ops.Mean(input_tensor, axis=axis, keep_dims=keep_dims)
Exemplo n.º 2
0
def reduce_mean(input_tensor,
                axis=None,
                keep_dims=False,
                name=None,
                reduction_indices=None):
    """
    Computes the mean of elements across dimensions of a tensor.

      Reduces `input_tensor` along the dimensions given in `axis`.
      Unless `keep_dims` is true, the rank of the tensor is reduced by 1 for each
      entry in `axis`. If `keep_dims` is true, the reduced dimensions
      are retained with length 1.

      If `axis` has no entries, all dimensions are reduced, and a
      tensor with a single element is returned.

      For example:

      ```python
      # 'x' is [[1., 1.]
      #         [2., 2.]]
      tf.reduce_mean(x) ==> 1.5
      tf.reduce_mean(x, 0) ==> [1.5, 1.5]
      tf.reduce_mean(x, 1) ==> [1.,  2.]
      ```

      Args:
        input_tensor: The tensor to reduce. Should have numeric type.
        axis: The dimensions to reduce. If `None` (the default),
          reduces all dimensions.
        keep_dims: If true, retains reduced dimensions with length 1.
        name: A name for the operation (optional).
        reduction_indices: The old (deprecated) name for axis.

      Returns:
        The reduced tensor.

    """

    if reduction_indices is not None:
        if axis is not None:
            raise ValueError(
                "cannot specify both 'axis' and 'reduction_indices'.")
        axis = reduction_indices
    elif axis is None:
        axis = -1  # reduce all
    if isinstance(axis, list) or isinstance(axis,
                                            tuple):  # reduce continuously
        if len(axis) < 1:
            raise RuntimeError('reduce axes should at least have one.')
        if len(axis) == 1:
            return ops.Mean(input_tensor, axis=axis[0], keep_dims=keep_dims)
        else:
            ret = ops.Mean(input_tensor, axis=axis[0], keep_dims=True)
            for i in xrange(1, len(axis) - 1):
                ret = ops.Mean(ret, axis=axis[i], keep_dims=True)
            return ops.Mean(ret, axis=axis[len(axis) - 1], keep_dims=keep_dims)
    else:
        return ops.Mean(input_tensor, axis=axis, keep_dims=keep_dims)
Exemplo n.º 3
0
def reduce_mean(
    input_tensor,
    axis=None,
    keep_dims=False,
    name=None,
    reduction_indices=None,
):
    if reduction_indices is not None:
        if axis is not None:
            raise ValueError(
                "cannot specify both 'axis' and 'reduction_indices'.")
        axis = reduction_indices
    return _ops.Mean(
        input_tensor,
        axes=axis,
        keep_dims=keep_dims,
        name=name,
    )
Exemplo n.º 4
0
def mean(input, axis=None, keepdims=False, **kwargs):
    """Compute the mean along the given axis.

    Parameters
    ----------
    input : Tensor
        The input tensor.
    axis : int
        The axis to compute. Default is ``None`` (Along all axes).
    keep_dims : boolean
        Whether to keep dims after computing.

    Returns
    -------
    Tensor
        The mean result.

    """
    if axis is None: axis = -1
    return ops.Mean(input, axis=axis, keep_dims=keepdims)