-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtensorFlowIntro.py~
37 lines (29 loc) · 1011 Bytes
/
tensorFlowIntro.py~
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
#tensorflow is matrix manipulation libraries
#a tensor is pretty much just an array of any size
#tensorflow is just functions on arrays
#first define the model in abstract terms and then you run the model and get results back
import tensorflow as tf
# creates nodes in a graph
# "construction phase"
x1 = tf.constant(5)
x2 = tf.constant(6)
#can multiply them
result = tf.mul(x1,x2)
print(result)
# defines our session and launches graph
sess = tf.Session()
# runs result
print(sess.run(result))
#can assign the output from the session to a new variable
output = sess.run(result)
print(output)
#close the session to free up reasources
sess.close()
'''
You can also use TensorFlow on multiple devices, and even multiple distributed machines. An example for running some computations on a specific GPU would be something like:
'''
with tf.Session() as sess:
with tf.device("/gpu:1"):
matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.],[2.]])
product = tf.matmul(matrix1, matrix2)