DAY 18
0

## Day18 Intro to TensorFlow 2

``````a = np.array([5, 3, 8])
b = np.array([3, -1, 2])
print(c)
``````

Build the graph

``````a = tf.constant([5, 3, 8])
b = tf.constant([3, -1, 2])
print(c)
``````

Run the graph

``````with tf.Session() as sess:
result = sess.run(c)
print(result)
``````

Using a feed_dict

``````a = tf.placeholder(dtype=tf.int32, shape=(None,))  # batchsize x scalar
b = tf.placeholder(dtype=tf.int32, shape=(None,))
with tf.Session() as sess:
result = sess.run(c, feed_dict={
a: [3, 4, 5],
b: [-1, 2, 3]
})
print(result)
``````

``````def compute_area(sides):
# slice the input to get the sides
a = sides[:,0]  # 5.0, 2.3
b = sides[:,1]  # 3.0, 4.1
c = sides[:,2]  # 7.1, 4.8

# Heron's formula
s = (a + b + c) * 0.5   # (a + b) is a short-cut to tf.add(a, b)
areasq = s * (s - a) * (s - b) * (s - c) # (a * b) is a short-cut to tf.multiply(a, b), not tf.matmul(a, b)
return tf.sqrt(areasq)

with tf.Session() as sess:
# pass in two triangles
area = compute_area(tf.constant([
[5.0, 3.0, 7.1],
[2.3, 4.1, 4.8]
]))
result = sess.run(area)
print(result)
``````