In [ ]:
# Write a program using tensorflow to calculate :
$$y=mx+c$$
In [68]:
import tensorflow as tf
with tf.name_scope("var"):
with tf.name_scope("mean_x"):
a=tf.constant([5.0,7.0,20.2,17.32],shape=[1,4],name='a')
b=tf.constant([7.0,9.0,19.0,18.0],shape=[1,4],name='b')
x=tf.reduce_mean(a)
sess=tf.Session()
print("mean",sess.run(x))
#mean x
In [69]:
#mean of y
with tf.name_scope("mean_y"):
y=tf.reduce_mean(b)
sess=tf.Session()
print("mean",sess.run(y))
In [70]:
#variance of x
d=tf.subtract(a,x)
sess=tf.Session()
print(sess.run(d ))
e=tf.square(d)
f=tf.reduce_sum(e)
sess=tf.Session()
print(sess.run(f))
In [71]:
#covariance
with tf.name_scope("covariance"):
g=tf.subtract(b,y)
sess=tf.Session()
g=tf.multiply(d,g)
h=tf.reduce_sum(g)
print(sess.run(h))
In [72]:
#value of c
with tf.name_scope("value_of_c"):
j=tf.divide(h,f)
print(sess.run(j))
In [73]:
#m value
with tf.name_scope("value_m"):
i=tf.multiply(j,x)
k=tf.subtract(y,i)
print(sess.run(j))
In [76]:
with tf.Session() as lb:
Writer =tf.summary.FileWriter("/tmp/tboard/output3",lb.graph)
Writer.close()
In [ ]:
In [ ]: