Tensorflow Placeholder with Example of Calculating Area of Triangle.
Run the code here: https://repl.it/@VinitKhandelwal/tensorflow-placeholder-area-triangle
OUTPUT
[6.278497 4.709139]
Run the code here: https://repl.it/@VinitKhandelwal/tensorflow-placeholder-area-triangle
import tensorflow as tf
def compute_area(sides):
a = sides[:, 0]
b = sides[:, 1]
c = sides[:, 2]
s = (a+b+c)*0.5
areasq = s*(s-a)*(s-b)*(s-c)
return tf.sqrt(areasq)
with tf.Session() as sess:
sides = tf.placeholder(tf.float32, shape=(None, 3))
area = compute_area(sides)
result = sess.run(area, feed_dict={sides:[[5.0, 3.0, 7.1], [2.3, 4.1, 4.8]]})
print(result)
[6.278497 4.709139]
Comments
Post a Comment