Calculating percentage of number with Tensorflow
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Drifting Through My Dreams
--
Chapters
00:00 Calculating Percentage Of Number With Tensorflow
00:29 Answer 1 Score 6
01:14 Accepted Answer Score 2
01:35 Thank you
--
Full question
https://stackoverflow.com/questions/5482...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #tensorflow
#avk47
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Drifting Through My Dreams
--
Chapters
00:00 Calculating Percentage Of Number With Tensorflow
00:29 Answer 1 Score 6
01:14 Accepted Answer Score 2
01:35 Thank you
--
Full question
https://stackoverflow.com/questions/5482...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #tensorflow
#avk47
ANSWER 1
Score 6
In the print statements you get,
<tf.Tensor 'Mul_4:0' shape=() dtype=int32>
And other such statements. This is because Python is printing out the Tensor Objects and not their values. There are two methods to solve this .
Enable eager execution.
import tensorflow as tf tf.enable_eager_execution()
This will enable eager mode and you will get values of the tensors instead of the Tensor objects. This initializes the tensors immediately as they are declared ( and hence eager ).
Using
tf.Session()A tf.Session() objects runs and evaluates tensors in the graph. It runs on graph mode and not eager mode.with tf.Session as session: print( session.run( div ) )
ACCEPTED ANSWER
Score 2
Try this it will certainly help:
>>> import tensorflow as tf
>>> a = tf.placeholder(tf.float32)
>>> b = tf.placeholder(tf.float32)
>>> sess = tf.Session()
>>> percentage = tf.divide(tf.multiply(a,100),b)
>>> sess.run(tf.global_variables_initializer())
>>> sess.run(percentage,feed_dict={a:4,b:20})
20.0
>>> sess.run(percentage,feed_dict={a:50,b:50})
100.0
>>> sess.close()
You can refer to simple example:
https://stackoverflow.com/a/39747526/4948889
Hope this helps.