- 텐서 조작(Tensor Manipulation)에 대해 알아본다.
핵심키워드
- 텐서(Tensor)
- 넘파이(NumPy)
- 텐서 조작(Tensor Manipulation)
1. Tensor는 배열의 집합이다.
2. 차원의 수는 Rank와 같은말이다.
3. 배열의 차원에따라 불리는 이름이 달라진다.
PyTorch Tensor
torch.tensor로 tensor를 만들어낸후 torch.** 의 함수로 각종 계산을 할 수 있다.
TORCH.TENSOR.ADD
Tensor.add(other, *, alpha=1) → Tensor
Add a scalar or tensor to self tensor. If both alpha and other are specified, each element of other is scaled by alpha before being used.
When other is a tensor, the shape of other must be broadcastable with the shape of the underlying tensor
See torch.add()
NumPy는 쉽게 Tensor를 표현할 수 있다?
일반적으로 1차원의 넘파이 array를 벡터(vector), 2차원을 행렬(matrix), 3차원부터는 텐서(tensor)라고 합니다. 넘파이 array의 차원이나 데이터 크기(개수)를 보기위해서
>> np.ndim #3부터는 tensor라고 보면 된다
>> np.size
를 사용합니다.
텐서(Tensor)는 다차원 배열입니다. 넘파이(NumPy) ndarray 객체와 비슷하며, tf.Tensor 객체는 데이터 타입과 크기를 가지고 있습니다. 또한 tf.Tensor는 GPU와 같은 가속기 메모리에 상주할 수 있습니다. 텐서플로우는 텐서를 생성하고 이용할 수 있는 풍부한 연산 라이브러리(ex. tf.add, tf.matmul, tf.linalg.inv 등.)를 제공합니다. 이러한 연산은 자동으로 텐서를 파이썬 네이티브(native) 타입으로 변환합니다.
'AI > PyTorch' 카테고리의 다른 글
[PyTorch] Multivariable Linear Regression (0) | 2021.06.01 |
---|---|
[PyTorch] Linear Regression 작성하기 (0) | 2021.06.01 |
[PyTorch] package (0) | 2021.05.24 |
[pyTorch] 이미지 여는 방법 (0) | 2021.05.12 |
[PyTorch] torch view, squeeze, unsqueeze (0) | 2021.04.27 |