MJay
TensorFLow Basic Syntax 본문
import tensorflow as tf
In [3]:
print (tf.__version__)
In [12]:
hello = tf.constant("Hello ")
In [13]:
world = tf.constant("World")
In [14]:
type(hello)
Out[14]:
In [15]:
print(hello)
In [16]:
with tf.Session() as sess:
result = sess.run(hello + world)
In [17]:
print(result)
In [18]:
a = tf.constant(10)
In [21]:
b = tf.constant(20)
In [22]:
a + b
Out[22]:
In [23]:
a + b
Out[23]:
In [24]:
a + b
Out[24]:
In [25]:
type(a)
Out[25]:
In [26]:
with tf.Session() as sess:
result = sess.run(a+b)
In [27]:
result
Out[27]:
In [28]:
const = tf.constant(10)
In [31]:
fill_mat = tf.fill((4,4),10)
In [32]:
myzeros = tf.zeros((4,4))
In [33]:
myones = tf.ones((4,4))
In [34]:
myrandn = tf.random_normal((4,4), mean=0, stddev=1.0)
In [35]:
myrandu = tf.random_uniform((4,4),minval=0, maxval =1)
In [36]:
my_ops = [const,fill_mat,myzeros,myones, myrandn, myrandu]
In [37]:
sess = tf.InteractiveSession()
In [39]:
for op in my_ops:
print(op.eval()) # or you can do sess.run(op)
print("\n")
In [41]:
a = tf.constant([[1,2],[3,4]])
In [42]:
a.get_shape()
Out[42]:
In [43]:
b = tf.constant([[10],[20]])
In [44]:
b.get_shape()
Out[44]:
In [45]:
result = tf.matmul(a,b)
In [46]:
sess.run(result)
Out[46]:
In [47]:
result.eval() # or you can do sess.run(result)
Out[47]:
In [ ]: