-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtensorflow_basic.py
More file actions
40 lines (29 loc) · 890 Bytes
/
tensorflow_basic.py
File metadata and controls
40 lines (29 loc) · 890 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
35
36
37
38
39
40
# tensorflow_basic.py
import tensorflow as tf
hello = tf.constant("Hello, Tensorflow!")
print(hello)
sess = tf.Session()
result = sess.run(hello)
print(result)
node1 = tf.constant(3.0, tf.float32)
node2 = tf.constant(4.0)
node3 = tf.add(node1, node2)
print("node1:", node1)
print("node2:", node2)
print("node3:", node3)
sess = tf.Session()
# print("sess.run([node1, node2]) : ", sess.run([node1, node2]))
print("sess.run(node3) : ", sess.run(node3))
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
adder_node = tf.add(a , b)
sess = tf.Session()
print(sess.run(adder_node, feed_dict={a:3, b:4.5}))
print(sess.run(adder_node, feed_dict={a:[1,3], b:[2,4]}))
# Variable 사용법
a1 = tf.Variable(4.0, tf.float32)
b1 = tf.Variable(7.5, tf.float32)
adder_node2 = tf.add(a1, b1)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
print(sess.run(adder_node2))