In [1]:
import tensorflow as tf
import tensorflow as tf
a=tf.constant([2.33,3.0,3.5,4.0],shape=[1,4],name='x')
b=tf.constant([4.5,6.5,7.0,8.5],shape=[1,4],name='y')
with tf.name_scope("mean"):
with tf.name_scope("mean_x_y"):
x1=tf.reduce_mean(a)
y1=tf.reduce_mean(b)
sess=tf.Session()
print("mean of a and b")
print(sess.run(x1))
print(sess.run(y1))
with tf.name_scope("variance"):
with tf.name_scope("scope_sub1"):
x=tf.subtract(a,x1)
sess1=tf.Session()
print(sess1.run(x))
with tf.name_scope("scope_sub2"):
y=tf.subtract(b,y1)
sess2=tf.Session()
print(sess2.run(y))
with tf.name_scope("scope_square"):
a1=tf.multiply(x,x)
sess3=tf.Session()
print(sess3.run(a1))
with tf.name_scope("scope_summation"):
var=tf.reduce_sum(a1)
sess4=tf.Session()
print("variance")
print(sess4.run(var))
with tf.name_scope("covariance"):
with tf.name_scope("multiplication"):
mul1=tf.multiply(a,b)
sess5=tf.Session()
print(sess5.run(mul1))
with tf.name_scope("scope_summation2"):
covar=tf.reduce_sum(mul1)
sess6=tf.Session()
print("covariance")
print(sess6.run(covar))
In [6]:
##(a-b)^2
import tensorflow as tf
v1=tf.constant(3)
v2=tf.constant(4)
with tf.name_scope("MyOperationGroup"):
with tf.name_scope("Scope_A"):
a = tf.multiply(v1,v1)
b = tf.multiply(v2,v2)
with tf.name_scope("Scope_B"):
c = tf.add(a, b, name="And_These_ones")
d = tf.multiply(v1, v2, name="Multiply_these_numbers")
with tf.name_scope("Scope_C"):
e = tf.multiply(2, d, name="B_add")
g = tf.subtract(c,e)
with tf.Session() as sess:
writer = tf.summary.FileWriter("/tmp/tboard/output_la1", sess.graph)
print(sess.run(g))
writer.close()
In [9]:
import tensorflow as tf
v3=tf.constant(3)
v4=tf.constant(2)
with tf.name_scope("MyOperationGroup"):
with tf.name_scope("Scope_A"):
a = tf.multiply(v3,v3)
b = tf.multiply(v4,v4)
with tf.name_scope("Scope_B"):
c = tf.add(a, b, name="And_These_ones")
d = tf.multiply(v3, v4, name="Multiply_these_numbers")
with tf.name_scope("Scope_C"):
e=tf.subtract(c,d, name="subtrating")
#e = tf.multiply(2, d, name="B_add")
f=tf.add(v3,v4)
with tf.name_scope("Scope_D"):
g = tf.multiply(f,e)
with tf.Session() as sess:
writer = tf.summary.FileWriter("/tmp/tboard/output_la2", sess.graph)
print(sess.run(g))
writer.close()
In [ ]: