TensorFlow. tf.reduce_mean
2017-05-09 13:38
519 查看
tf.reduce_mean
tf.reduce_mean(input_tensor,reduction_indices=None,keep_dims=False,name=None)
Computes the mean of elements across dimensions of a tensor.
按某一维度(reduction_indices)计算一个张量的个元素的平均值。
Reduces input_tensor along the dimensions given in reduction_indices. Unless keep_dims is true, the rank of the tensor is reduced by 1 for each entry in reduction_indices.
If keep_dims is true, the reduced dimensions are retained with length 1.
沿着reduction_indices给出的维度方向降维。如果keep_dims等于true,则按reduction_indices给出的降维的尺寸保留为1维,如果是False,则降维到1维。
If reduction_indices has no entries, all dimensions are reduced, and a tensor with a single element is returned.
如果reduction_indices没有指定,则所有维度都要降维,返回一个含有单个元素的张量。
举例:
import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.constant(value=[[1.,2.,3.],[4.,5.,6.],[7.,8.,9.]],dtype=tf.float32,shape=[3,3],name=”x”)
print sess.run(x)
print x
mean1 = tf.reduce_mean(input_tensor=x, reduction_indices=None, keep_dims=False)
mean1 = tf.reduce_mean(input_tensor=x, reduction_indices=None, keep_dims=False)
mean2 = tf.reduce_mean(input_tensor=x, reduction_indices=0, keep_dims=False)
mean3 = tf.reduce_mean(input_tensor=x, reduction_indices=1, keep_dims=False)
mean4 = tf.reduce_mean(input_tensor=x, reduction_indices=0, keep_dims=True)
mean5 = tf.reduce_mean(input_tensor=x, reduction_indices=1, keep_dims=True)
mean6 = tf.reduce_mean(input_tensor=x, reduction_indices=None, keep_dims=True)
print sess.run(mean1)
print mean1
print sess.run(mean2)
print mean2
print sess.run(mean3)
print mean3
print sess.run(mean4)
print mean4
print sess.run(mean5)
print mean5
print sess.run(mean6)
print mean6
输出:
[[ 1. 2. 3.]
[ 4. 5. 6.]
[ 7. 8. 9.]]
Tensor(“x:0”, shape=(3, 3), dtype=float32)
5.0
Tensor(“Mean_2:0”, shape=(), dtype=float32)
[ 4. 5. 6.]
Tensor(“Mean_3:0”, shape=(3,), dtype=float32)
[ 2. 5. 8.]
Tensor(“Mean_4:0”, shape=(3,), dtype=float32)
[[ 4. 5. 6.]]
Tensor(“Mean_5:0”, shape=(1, 3), dtype=float32)
[[ 2.]
[ 5.]
[ 8.]]
Tensor(“Mean_6:0”, shape=(3, 1), dtype=float32)
[[ 5.]]
Tensor(“Mean_1:0”, shape=(1, 1), dtype=float32)
Args:
input_tensor: The tensor to reduce. Should have numeric type.
reduction_indices: 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).
Returns:
The reduced tensor.
参数说明:
Input_tensor:被降维的张量必须其数据类型必须被预先指定。
reduction_indices:降维的维度如果为None(default),则所有维度都要降维。
keep_dims:如果keep_dims为true,则降维的尺寸将保留为1
name:降维操作的名字。
返回一个降维后的张量。
如发现文章中有错误,请不吝指教
tf.reduce_mean(input_tensor,reduction_indices=None,keep_dims=False,name=None)
Computes the mean of elements across dimensions of a tensor.
按某一维度(reduction_indices)计算一个张量的个元素的平均值。
Reduces input_tensor along the dimensions given in reduction_indices. Unless keep_dims is true, the rank of the tensor is reduced by 1 for each entry in reduction_indices.
If keep_dims is true, the reduced dimensions are retained with length 1.
沿着reduction_indices给出的维度方向降维。如果keep_dims等于true,则按reduction_indices给出的降维的尺寸保留为1维,如果是False,则降维到1维。
If reduction_indices has no entries, all dimensions are reduced, and a tensor with a single element is returned.
如果reduction_indices没有指定,则所有维度都要降维,返回一个含有单个元素的张量。
举例:
import tensorflow as tf
sess = tf.InteractiveSession()
x = tf.constant(value=[[1.,2.,3.],[4.,5.,6.],[7.,8.,9.]],dtype=tf.float32,shape=[3,3],name=”x”)
print sess.run(x)
print x
mean1 = tf.reduce_mean(input_tensor=x, reduction_indices=None, keep_dims=False)
mean1 = tf.reduce_mean(input_tensor=x, reduction_indices=None, keep_dims=False)
mean2 = tf.reduce_mean(input_tensor=x, reduction_indices=0, keep_dims=False)
mean3 = tf.reduce_mean(input_tensor=x, reduction_indices=1, keep_dims=False)
mean4 = tf.reduce_mean(input_tensor=x, reduction_indices=0, keep_dims=True)
mean5 = tf.reduce_mean(input_tensor=x, reduction_indices=1, keep_dims=True)
mean6 = tf.reduce_mean(input_tensor=x, reduction_indices=None, keep_dims=True)
print sess.run(mean1)
print mean1
print sess.run(mean2)
print mean2
print sess.run(mean3)
print mean3
print sess.run(mean4)
print mean4
print sess.run(mean5)
print mean5
print sess.run(mean6)
print mean6
输出:
[[ 1. 2. 3.]
[ 4. 5. 6.]
[ 7. 8. 9.]]
Tensor(“x:0”, shape=(3, 3), dtype=float32)
5.0
Tensor(“Mean_2:0”, shape=(), dtype=float32)
[ 4. 5. 6.]
Tensor(“Mean_3:0”, shape=(3,), dtype=float32)
[ 2. 5. 8.]
Tensor(“Mean_4:0”, shape=(3,), dtype=float32)
[[ 4. 5. 6.]]
Tensor(“Mean_5:0”, shape=(1, 3), dtype=float32)
[[ 2.]
[ 5.]
[ 8.]]
Tensor(“Mean_6:0”, shape=(3, 1), dtype=float32)
[[ 5.]]
Tensor(“Mean_1:0”, shape=(1, 1), dtype=float32)
Args:
input_tensor: The tensor to reduce. Should have numeric type.
reduction_indices: 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).
Returns:
The reduced tensor.
参数说明:
Input_tensor:被降维的张量必须其数据类型必须被预先指定。
reduction_indices:降维的维度如果为None(default),则所有维度都要降维。
keep_dims:如果keep_dims为true,则降维的尺寸将保留为1
name:降维操作的名字。
返回一个降维后的张量。
如发现文章中有错误,请不吝指教
相关文章推荐
- tensorflow tf.reduce_mean
- tensorflow学习之常用函数总结:tensorflow.reduce_mean()函数
- tensorflow API:tf.reduce_sum
- TensorFlow reduce_mean
- tf.Reducemean
- TensorFlow resize_images函数导致TFRecord产生形状不匹配
- TensorFlow tf.clip_by_value tf.select 绝对值用法!
- Tensorflow serving(tf_serving) 安装测试说明
- tensorflow tf.stack tf.unstack 实例
- tensorflow API学习——tf.strided_slice
- tf.nn.embedding_lookup TensorFlow embedding_lookup 函数最简单实例
- tensorflow:tf.reduce_mean()和tf.reduce_sum()
- tf.reducemean()到底是什么意思?
- tensorflow API:tf.slice
- tensorflow学习之常用函数总结:tensorflow官方例子中的诸如tf.reduce_mean()这类函数
- tensorflow function笔记: tf.expand_dims and tf.squeeze
- 解决PyCharm [import tensorflow as tf]报错
- 池化操作 tensorflow tf.nn.max_pool
- TensorFlow TFRecord数据集的生成与显示
- tensorflow tf.group