In [65]:
import tensorflow as tf
import numpy as np

In [2]:
a = tf.constant(2)
b = tf.constant(3)
c = a + b

In [3]:
print(c)


Tensor("add:0", shape=(), dtype=int32)

In [5]:
with tf.Session() as sess:
    print(sess.run(c))


5

In [56]:
a = tf.placeholder(shape=(), dtype = tf.int32)

In [57]:
b = tf.placeholder(shape=(),dtype = tf.int32)

In [58]:
c = tf.add(a, b)

In [59]:
print(c)


Tensor("Add_7:0", shape=(), dtype=int32)

In [60]:
with tf.Session() as sess:
    print(sess.run(c, feed_dict={a:3, b:4}))


7

In [61]:
a = tf.placeholder(shape=(2,), dtype=tf.int32)
b = tf.placeholder(shape=(2,), dtype=tf.int32)
c = a + b

In [62]:
with tf.Session() as sess:
    print(sess.run(c, feed_dict={a:[1,1], b:[2,2]}))


[3 3]

In [63]:
a = tf.placeholder(shape=(2,2), dtype=tf.int32)
b = tf.placeholder(shape=(2,2), dtype=tf.int32)
c = a+b

In [64]:
with tf.Session() as sess:
    print(sess.run(c, feed_dict={a: [[1,1],[1,1]], b: [[2,2],[2,2]]}))


[[3 3]
 [3 3]]

In [73]:
a = np.array([1,2,3])

In [74]:
a.shape


Out[74]:
(3,)

In [75]:
b = np.array([[1,1],[2,2]])

In [76]:
b.shape


Out[76]:
(2, 2)

In [77]:
c = np.array(3)

In [78]:
c.shape


Out[78]:
()

In [82]:
c  # 스칼라(0차원 텐서)


Out[82]:
array(3)

In [83]:
a #벡터 (1차원 텐서)


Out[83]:
array([1, 2, 3])

In [84]:
b #행렬 (2차원 텐서)


Out[84]:
array([[1, 1],
       [2, 2]])

In [87]:
d = np.array([[[1,2],[2,3]],[[3,4],[2,3]]])

In [88]:
d.shape  #3차원 텐서


Out[88]:
(2, 2, 2)

In [89]:
d


Out[89]:
array([[[1, 2],
        [2, 3]],

       [[3, 4],
        [2, 3]]])

In [90]:
a = np.array([[1,1],[1,1]])

In [91]:
b = np.array([[2,2],[2,2]])

In [92]:
a.shape


Out[92]:
(2, 2)

In [93]:
a


Out[93]:
array([[1, 1],
       [1, 1]])

In [94]:
b


Out[94]:
array([[2, 2],
       [2, 2]])

In [95]:
c=a+b

In [96]:
c


Out[96]:
array([[3, 3],
       [3, 3]])

In [97]:
a = np.array([3,3])

In [98]:
a


Out[98]:
array([3, 3])

In [99]:
c = np.dot(a,b)

In [100]:
c


Out[100]:
array([12, 12])

In [ ]: