In [1]:
import numpy as np
import tensorflow as tf
a = tf.constant([34.3, 33.0, 21.5, 4.0, 5.8, 27.5], shape=[1,6], name='a')
b = tf.constant([43.3, 22.0, 21.5, 5.0, 6.7, 45.5], shape=[1,6], name='b')
with tf.name_scope("mean_A"):
mean_a=tf.reduce_mean(a)
ses1=tf.Session()
print(ses1.run(mean_a))
with tf.name_scope("mean_B"):
mean_b=tf.reduce_mean(b)
ses2=tf.Session()
print(ses2.run(mean_b))
with tf.name_scope("variance"):
d=tf.subtract(a,mean_a)
sess=tf.Session()
print(sess.run(d))
e=tf.square(d)
variance=tf.reduce_sum(e)
sess=tf.Session()
print(sess.run(variance))
In [2]:
with tf.name_scope("covariance"):
g=tf.subtract(b,mean_b)
sess=tf.Session()
g=tf.multiply(d,g)
cov_xy=tf.reduce_sum(g)
cov=tf.divide(cov_xy,5)
print(sess.run(cov))
In [3]:
with tf.name_scope("value_of_m"):
c=tf.divide(cov,variance)
print(sess.run(c))
with tf.name_scope("value_of_c"):
i=tf.multiply(c,mean_a)
k=tf.subtract(mean_b,i)
print(sess.run(k))
with tf.Session() as sess:
writer = tf.summary.FileWriter("/tmp/tboard/output1", sess.graph)
writer.close()
In [ ]:
In [ ]: