in Education by
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. If None (the default), 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] are [1.5,1.5] but what's going on with tf.reduce_mean(x,1)? Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
The function of numpy.mean and tensorflow.reduce_mean are the same. Numpy example: c = np.array([[3.,4], [5.,6], [6.,7]]) print(np.mean(c,1)) Output [ 3.5 5.5 6.5] [ 3.5 5.5 6.5] TensorFlow Example: Mean = tf.reduce_mean(c,1) with tf.Session() as sess: result = sess.run(Mean) print(result) Output [ 3.5 5.5 6.5] [ 3.5 5.5 6.5] In the above example, axis(numpy) or reduction_indices(tensorflow) is 1, it computes mean across (3,4) and (5,6) and (6,7), so 1 defines across which axis the mean is computed. When it is 0, the mean is computed across(3,5,6) and (4,6,7), and so on Numpy operation can be computed anywhere in the code of python. But for a tensorflow operation, it must be done inside a TensorFlow Session. So when you need to perform any computation for your TensorFlow graph, it must be done inside a tensorflow Session. For example. NumPy: npMean = np.mean(c) print(npMean+1) TensorFlow: tfMean = tf.reduce_mean(c) Add = tfMean + 1 with tf.Session() as sess: result = sess.run(Add) print(result) Hope this answer helps.

Related questions

0 votes
    I am building a model for binary classification problem where each of my data points is of 300 dimensions (I am ... the 300 dim space? Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    I try to learn and implement a simple genetic algorithm library for my project. At this time, evolution, ... Gaussian distribution?.) Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
0 votes
    What is the difference between informed and uninformed searches? Can you explain this with some examples? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I was looking at the docs of TensorFlow about tf.nn.conv2d here. But I can't understand what it does or ... it raised the question. Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    What is the difference between back-propagation and feed-forward neural networks? By googling and reading, I found ... feed-forward? Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    In this video from Sebastian Thrun, he says that supervised learning works with "labeled" data and unsupervised ... basic difference. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I'm Working on document classification tasks in java. Both algorithms came highly recommended, what are the ... Processing tasks? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    From what I've read so far they seem very similar. Differential evolution uses floating point numbers instead, and ... of both. Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    I have trouble understanding the difference (if there is one) between roc_auc_score() and auc() in scikit-learn. I ... out why. Thanks! Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
0 votes
    I'm learning the difference between the various machine learning algorithms. I understand that the implementations of ... for that? Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    I am looking for an open source neural network library. So far, I have looked at FANN, WEKA, and OpenNN. Are the ... , and ease of use. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Like lots of you guys on SO, I often write in several languages. And when it comes to planning stuff, (or ... to this being possible? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm looking for some examples of robot/AI programming using Lisp. Are there any good online examples available ... in nature)? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm working through my AI textbook I got and I've come to the last homework problem for my section: "Implement the ... in C# or Java? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm teaching a kid programming, and am introducing some basic artificial intelligence concepts at the moment. To begin ... and boxes)? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
...