In [2]:
#(a−b)2=a2+b2−2ab
import tensorflow as tf
a=4
b=2
with tf.name_scope("lab1_assgn1"):
with tf.name_scope("Scope_A"):
x = tf.multiply(a, a)
y = tf.multiply(b, b)
with tf.name_scope("Scope_B"):
z = tf.multiply(2, a)
h = tf.multiply(z, b)
with tf.name_scope("Scope_C"):
d = tf.add(x, y)
s = tf.subtract(d, h)
with tf.Session() as sess:
writer = tf.summary.FileWriter("/tmp/tboard/output4", sess.graph)
print(sess.run(s))
writer.close()
In [5]:
#(a3+b3)=(a+b)(a2−ab+b2)
import tensorflow as tf
v1=tf.constant(8)
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.subtract(c,d, name="subtrating")
f=tf.add(v1,v2)
with tf.name_scope("Scope_D"):
g = tf.multiply(f,e)
with tf.Session() as lb2:
writer = tf.summary.FileWriter("/tmp/tboard/output5", lb2.graph)
print(lb2.run(g))
writer.close()