[1] 텐서플로우를 위한 자료형
15384 단어 tensorflowtensorflow
상수(constant)
1차원 배열의 연산
import tensorflow as tf
t1 = tf.constant([1,2,3])
t2 = tf.constant([1,2,3])
print(t1+t2)
tf.Tensor([2 4 6], shape=(3,), dtype=int32)
2차원 배열의 연산
import tensorflow as tf
t1 = tf.constant([[1,2],
[2,3]])
t2 = tf.constant([[1,2],
[2,3]])
print(t1+t2)
tf.Tensor(
[[2 4]
[4 6]], shape=(2, 2), dtype=int32)
연산 메서드
tf.add()
tf.subtract()
tf.divide()
tf.multiply()
tf.matmul() # 행열의 곱셈연산(단순곱셈과다름)
print(tf.add(t1,t2)) # 예시
0으로 가득찬 배열 만들기
t1 = tf.zeros(10)
print(t1)
tf.Tensor([0. 0. 0. 0. 0. 0. 0. 0. 0. 0.], shape=(10,), dtype=float32)
##
t1 = tf.zeros([2,3])
print(t1)
tf.Tensor(
[[0. 0. 0.]
[0. 0. 0.]], shape=(2, 3), dtype=float32)
##
t1 = tf.zeros([2,3,4])
print(t1)
tf.Tensor(
[[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]
[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]], shape=(2, 3, 4), dtype=float32)
shape
t1 = tf.zeros([2,3,4])
print(t1.shape)
# (2, 3, 4)
import tensorflow as tf
t1 = tf.constant([1,2,3])
t2 = tf.constant([1,2,3])
print(t1+t2)
tf.Tensor([2 4 6], shape=(3,), dtype=int32)
import tensorflow as tf
t1 = tf.constant([[1,2],
[2,3]])
t2 = tf.constant([[1,2],
[2,3]])
print(t1+t2)
tf.Tensor(
[[2 4]
[4 6]], shape=(2, 2), dtype=int32)
tf.add()
tf.subtract()
tf.divide()
tf.multiply()
tf.matmul() # 행열의 곱셈연산(단순곱셈과다름)
print(tf.add(t1,t2)) # 예시
t1 = tf.zeros(10)
print(t1)
tf.Tensor([0. 0. 0. 0. 0. 0. 0. 0. 0. 0.], shape=(10,), dtype=float32)
##
t1 = tf.zeros([2,3])
print(t1)
tf.Tensor(
[[0. 0. 0.]
[0. 0. 0.]], shape=(2, 3), dtype=float32)
##
t1 = tf.zeros([2,3,4])
print(t1)
tf.Tensor(
[[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]
[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]], shape=(2, 3, 4), dtype=float32)
t1 = tf.zeros([2,3,4])
print(t1.shape)
# (2, 3, 4)
텐서 자료형이 몇차원 배열인지 알려줌
dtype
t2 = tf.constant("노")
print(t2)
#tf.Tensor(b'\xeb\x85\xb8\xe3\x85\x91', shape=(), dtype=string)
dtype으로 데이터 타입정보를 가지고있음
ex) int, float, string...
변수(Variable)
w = tf.Variable(1.0) # 텐서플로우에서 weight(가중치)로 사용됨
print(w)
#<tf.Variable 'Variable:0' shape=() dtype=float32, numpy=1.0>
print(t.numpy()) # 값을 참조할 때
# 1.0
t.assign(3) # 변수니까 새로운값 할당 가능
print(t.numpy())
# 3
Author And Source
이 문제에 관하여([1] 텐서플로우를 위한 자료형), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://velog.io/@rhdxoals/1-텐서플로우를-위한-자료형
저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
w = tf.Variable(1.0) # 텐서플로우에서 weight(가중치)로 사용됨
print(w)
#<tf.Variable 'Variable:0' shape=() dtype=float32, numpy=1.0>
print(t.numpy()) # 값을 참조할 때
# 1.0
t.assign(3) # 변수니까 새로운값 할당 가능
print(t.numpy())
# 3
Author And Source
이 문제에 관하여([1] 텐서플로우를 위한 자료형), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@rhdxoals/1-텐서플로우를-위한-자료형저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)