Nel MNIST beginner tutorial, c'è accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
Differenza tra np.mean e tf.reduce_mean in Numpy e Tensorflow?
tf.cast
cambia sostanzialmente il tipo di tensore l'oggetto è, ma ciò che è la differenza tra tf.reduce_mean
e np.mean
?
Ecco il doc su 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. If `None` (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.]
Per un vettore 1D, sembra np.mean == tf.reduce_mean
ma non capisco cosa sta succedendo nel tf.reduce_mean(x, 1) ==> [1., 2.]
. tf.reduce_mean(x, 0) ==> [1.5, 1.5]
tipo di ha senso, dal momento che media di [1,2] e [1,2] sono [1.5,1.5] ma cosa succede con tf.reduce_mean(x,1)
?
producono risultati diversi [su valori interi] (http://stackoverflow.com/a/43713062/1090562) a causa della divisione in python –