【发布时间】:2016-03-18 02:48:13
【问题描述】:
在MNIST beginner tutorial中,有这样的说法
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
tf.cast基本上改变了对象的张量类型,但是tf.reduce_mean和np.mean有什么区别呢?
这是tf.reduce_mean上的文档:
reduce_mean(input_tensor, reduction_indices=None, keep_dims=False, name=None)
input_tensor: 要约简的张量。应该是数字类型。
reduction_indices:要减小的尺寸。如果None(默认值),则减少所有维度。# '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.]
对于一维向量,它看起来像 np.mean == tf.reduce_mean,但我不明白 tf.reduce_mean(x, 1) ==> [1., 2.] 中发生了什么。 tf.reduce_mean(x, 0) ==> [1.5, 1.5] 有点道理,因为 [1, 2] 和 [1, 2] 的平均值是 [1.5, 1.5],但是 tf.reduce_mean(x, 1) 是怎么回事?
【问题讨论】:
-
由于python中的划分,他们产生different results on integer values
-
对于刚接触 tensorflow 的人来说,一个重要的区别是:
tf.reduce_mean是多线程的,通常在您的 GPU 上计算,而np.mean是在单个 CPU 上计算的。此外,tf旨在处理一批数据,而np作用于单个数据实例。
标签: python numpy machine-learning mean tensorflow