→ 텐서플로우에서 처리된 결과값을 넘파이로 변환하여 주는 함수
# 텐서 -> 넘파이
a = tf.constant(3)
b = tf.constant(2)
t1 = tf.add(a, b)
print("t1 type = ", type(t1))
print("t1 = ", t1)
n1 = t1.numpy()
print("n1 type = ", type(n1))
print("n1 = ", n1)
→ numpy()의 값을 텐서플로우로 변환한다.
<aside> 💡 형변환이 필요한 경우에는 넘파이에서 미리 바꾸고 텐서로 넘기는 것이 좋다.
</aside>
<aside> 💡 dtype에서 float32를 쓴 이유는 보통 텐서플로우에서 실수형으로 사용하기 때문이다. 인공지능 학습 시 가장 많이 사용하는 형식이 float32
</aside>
# 넘파이 -> 텐서
a = tf.constant(3)
b = tf.constant(2)
t1 = tf.add(a, b)
n_square = np.square(t1, dtype= np.float32) # 넘파이, 강제 실수형 변환
c_tensor = tf.convert_to_tensor(n_square) # 넘파이 -> 텐서
print(c_tensor)
print(type(c_tensor))