텐서란?
Tensor는 multi-dimensional array를 나타내는 말로, TensorFlow의 기본 data type 이다.
텐서를 만들기 위해서는 간단하게 tf.constant 를 이용하여 만들 수 있다.
1.텐서 생성하기_기본형
hello = tf.constant([3,3], dtype=tf.float32)
결과는 넘파이의 array 와는 다르게 숫자와 함께 shape 과 데이터타입을 함께 출력한다.
tf.Tensor([3. 3.], shape=(2,), dtype=float32)
글자를 넣어서 만들 수도 있는데
hello = tf.constant('hello world')
이때의 결과는 다음과 같다.
tf.Tensor(b'hello world', shape=(), dtype=string)
2. 텐서 생성하기_array 형
x = tf.constant([[1.0, 2.0],
[3.0, 4.0]])
결과는 아래와 같다.
tf.Tensor(
[[1. 2.]
[3. 4.]], shape=(2, 2), dtype=float32)
'Pytorch > Summarize' 카테고리의 다른 글
1. 텐서(tensor)란?_array와 list를 이용하여 텐서 생성하기 (0) | 2022.08.24 |
---|
댓글