[Tensorflow] Tensorflow 기본 프로그래밍

Tensorflow 기본 프로그래밍

TF2.x의 기본 구현 방법에 대해서 알아본다.

import tensorflow as tf
print(tf.__version__)
## 2.1.0
random = tf.random.normal([1], dtype=tf.float32)
print(random)
## tf.Tensor([-1.5870395], shape=(1,), dtype=float32)
print(random.numpy())
## [-1.5870395]
a = tf.constant(10, dtype=tf.float32)
b = tf.constant(20, dtype=tf.float32)

c = a+b
print(c)
## tf.Tensor(30.0, shape=(), dtype=float32)
print(c.numpy())
## 30.0
a = tf.constant(10, dtype=tf.float32) 
d = 30
print((a+d).numpy())        # 40
tensor_d = tf.convert_to_tensorf(d)
print((a+tensor_d).numpy()) # 40
w = tf.Variable(tf.random.normal([1]), name='weight')
print(w.numpy())
## [0.966355]