Python으로 시작하는 TensorFlow
Isaiah Hull
Visiting Associate Professor of Finance, BI Norwegian Business School
add(), multiply(), matmul(), reduce_sum()gradient(), reshape(), random()| Operation | Use |
|---|---|
gradient() |
함수의 한 점에서 기울기 계산 |
reshape() |
텐서 형태 변경(예: 10x10 → 100x1) |
random() |
확률분포에서 뽑은 값으로 텐서 채움 |
많은 문제에서 함수의 최적점을 찾습니다.
gradient()로 구할 수 있습니다.


# Import tensorflow under the alias tf
import tensorflow as tf
# Define x
x = tf.Variable(-1.0)
# Define y within instance of GradientTape
with tf.GradientTape() as tape:
tape.watch(x)
y = tf.multiply(x, x)
# Evaluate the gradient of y at x = -1
g = tape.gradient(y, x)
print(g.numpy())
-2.0

# Import tensorflow as alias tf
import tensorflow as tf
# Generate grayscale image
gray = tf.random.uniform([2, 2], maxval=255, dtype='int32')
# Reshape grayscale image
gray = tf.reshape(gray, [2*2, 1])

# Import tensorflow as alias tf
import tensorflow as tf
# Generate color image
color = tf.random.uniform([2, 2, 3], maxval=255, dtype='int32')
# Reshape color image
color = tf.reshape(color, [2*2, 3])

Python으로 시작하는 TensorFlow