W samouczku dla początkujących MNIST znajduje się oświadczenie
accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float"))
tf.cast zasadniczo zmienia typ tensora obiektu, ale jaka jest różnica między tf.reduce_mean i np.mean?
Oto dokument dotyczący tf.reduce_mean:
reduce_mean(input_tensor, reduction_indices=None, keep_dims=False, name=None)
input_tensor: Tensor do zmniejszenia. Powinien mieć typ liczbowy.
reduction_indices: Wymiary do zmniejszenia. JeśliNone(defaut), zmniejsza wszystkie wymiary.# '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.]
Wygląda to na wektor 1D np.mean == tf.reduce_mean, ale nie rozumiem, co się dzieje tf.reduce_mean(x, 1) ==> [1., 2.]. tf.reduce_mean(x, 0) ==> [1.5, 1.5]trochę ma sens, skoro średnia [1, 2]i [1, 2]jest [1.5, 1.5], ale o co chodzi tf.reduce_mean(x, 1)?