Pytorch란 무엇인가요? - 연산 (Pytorch 학습 2)
1. 덧셈 import torch # 1 x = torch.ones(5, 3) y = torch.rand(5, 3) print(x + y) # 2 print(torch.add(x, y)) # 3 result = torch.empty(5, 3) torch.add(x, y, out=result) print(result) # 4 in-place y.add_(x) print(y) 위 출력 결과는 모두 동일하다. tensor([[1.5353, 1.6422, 1.8407], [1.9036, 1.7170, 1.7341], [1.9691, 1.9267, 1.1749], [1.5314, 1.8827, 1.8450], [1.7856, 1.8662, 1.8147]]) tensor([[1.5353, 1.6422, 1.8407..
2021. 4. 16.
Pytorch란 무엇인가요? - 시작하기 (Pytorch 학습 1)
1. 초기화되지 않은 행렬 선언 import torch x = torch.empty(5, 3) print(x) - 초기화되지 않은 행렬이 선언되었지만, 사용하기 전에는 명확히 알려진 값을 포함하고 있지는 않는다. - 위의 empty와 같이 초기화되지 않은 행렬이 생성되면 그 시점에 할당된 메모리에 존재하던 값들이 초기값. 출력 (shape : 5 x 3) tensor([[8.4490e-39, 9.6429e-39, 9.2755e-39], [1.0286e-38, 9.0919e-39, 8.9082e-39], [9.2755e-39, 8.4490e-39, 1.0194e-38], [9.0919e-39, 8.4490e-39, 9.6429e-39], [1.0653e-38, 9.6429e-39, 1.0745e-38]])..
2021. 4. 16.