-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtf_ex3_eager_api.py
More file actions
34 lines (28 loc) · 827 Bytes
/
tf_ex3_eager_api.py
File metadata and controls
34 lines (28 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import tensorflow as tf
# Set Eager API
tf.enable_eager_execution()
tfe = tf.contrib.eager
# Define constant tensors
a = tf.constant(2)
b = tf.constant(3)
# Run operations without tf.Session()
print("a: {}, b: {}".format(a, b))
c = a + b
d = a * b
print("Addition: a + b = {}".format(c))
print("Multiplication: a * b = {}\n".format(d))
# Create 2 constant tensors
a = tf.constant([[2., 1.],
[1., 0.]], dtype=tf.float32)
b = tf.constant([[3., 0.],
[5., 1.]], dtype=tf.float32)
# Run operations without tf.Session()
print("a:\n{}\nb:\n{}\n".format(a, b))
c = a + b
d = tf.matmul(a, b)
print("Addition: a + b = \n{}\n".format(c))
print("Multiplication: a * b = \n{}\n".format(d))
# Iterate through tensor a
for i in range(a.shape[0]):
for j in range(a.shape[1]):
print(a[i][j])