In [1]:
import tensorflow as tf
print(tf.__version__)


1.2.0

In [2]:
"""
아래는 

1 1 1
1 1 1 

행렬이다. 
"""

x = [[1,1,1],
     [1,1,1]]

y = [[[ 1, 2, 3],
      [40,20,30]],
     [[4,70,6],
      [7, 8,9]]]

In [3]:
sum = tf.reduce_sum(x)
sum1 = tf.reduce_sum(x, reduction_indices = 1)
sum2 = tf.reduce_sum(x, reduction_indices = 0)
sum3 = tf.reduce_sum(x, reduction_indices = 1, keep_dims = True)
sum4 = tf.reduce_sum(x, reduction_indices = [0, 1])
sum5 = tf.reduce_sum(x, reduction_indices = [1, 0])

In [4]:
sess = tf.Session()
print(sess.run(sum))
print(sess.run(sum1))
print(sess.run(sum2))
print(sess.run(sum3))
print(sess.run(sum4))
print(sess.run(sum5))


6
[3 3]
[2 2 2]
[[3]
 [3]]
6
6

In [5]:
#행렬에서 가장큰 값이 있는 인덱스를 리턴한다.
#벡터면 그냥 0써주면 된다.
sess.run(tf.arg_max(y,2))


Out[5]:
array([[2, 0],
       [1, 2]])

In [27]:
x = tf.Variable(initial_value=0, name='x')

In [28]:
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    for i in range(10):
        x = x + 1
        print(sess.run(x))


1
2
3
4
5
6
7
8
9
10

In [29]:
with tf.Session() as sess:
    tf.assign(x, 1)
    sess.run(tf.global_variables_initializer())
    
    for i in range(10):
#         tf.assign(x, 4)
        print(sess.run(x))


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-29-b2b2cb6ac1ef> in <module>()
      1 with tf.Session() as sess:
----> 2     tf.assign(x, 1)
      3     sess.run(tf.global_variables_initializer())
      4 
      5     for i in range(10):

/Users/jaegyuhan/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/state_ops.py in assign(ref, value, validate_shape, use_locking, name)
    270         ref, value, use_locking=use_locking, name=name,
    271         validate_shape=validate_shape)
--> 272   return ref.assign(value)

AttributeError: 'Tensor' object has no attribute 'assign'

In [10]:
help(tf.assign)


Help on function assign in module tensorflow.python.ops.state_ops:

assign(ref, value, validate_shape=None, use_locking=None, name=None)
    Update 'ref' by assigning 'value' to it.
    
    This operation outputs a Tensor that holds the new value of 'ref' after
      the value has been assigned. This makes it easier to chain operations
      that need to use the reset value.
    
    Args:
      ref: A mutable `Tensor`.
        Should be from a `Variable` node. May be uninitialized.
      value: A `Tensor`. Must have the same type as `ref`.
        The value to be assigned to the variable.
      validate_shape: An optional `bool`. Defaults to `True`.
        If true, the operation will validate that the shape
        of 'value' matches the shape of the Tensor being assigned to.  If false,
        'ref' will take on the shape of 'value'.
      use_locking: An optional `bool`. Defaults to `True`.
        If True, the assignment will be protected by a lock;
        otherwise the behavior is undefined, but may exhibit less contention.
      name: A name for the operation (optional).
    
    Returns:
      A `Tensor` that will hold the new value of 'ref' after
        the assignment has completed.


In [ ]: