In the MNIST beginner tutorial, there is the statement
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
tf.cast
basically changes the type of tensor the object is, but what is the difference between tf.reduce_mean
and np.mean
?
Here is the doc on tf.reduce_mean
:
reduce_mean(input_tensor, reduction_indices=None, keep_dims=False, name=None)
input_tensor
: The tensor to reduce. Should have numeric type.
reduction_indices
: The dimensions to reduce. IfNone
(the defaut), reduces all dimensions.# '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.]
For a 1D vector, it looks like np.mean == tf.reduce_mean
, but I don't understand what's happening in tf.reduce_mean(x, 1) ==> [1., 2.]
. tf.reduce_mean(x, 0) ==> [1.5, 1.5]
kind of makes sense, since mean of [1, 2]
and [1, 2]
is [1.5, 1.5]
, but what's going on with tf.reduce_mean(x, 1)
?