Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 머신러닝
- 프로그래머스
- Tensor
- pytorch
- 백준
- 협업 필터링
- 파이썬
- 분산 시스템
- wordcloud
- 추천시스템
- Cosine-similarity
- Python
- SGD
- Overfitting
- 시각화
- 코딩테스트
- TF-IDF
- 부스트캠프
- selenium
- 딥러닝
- 코테
- 추천 시스템
- codingtest
- 웹크롤링
- 데이터
- coursera
- 알고리즘
- 데이터 엔지니어링
- 웹스크래핑
- recommendation system
Archives
- Today
- Total
개발자식
[Pytorch] torch.sum (Tensor 요소 합) 본문
torch.sum()
- input 텐서에 있는 모든 요소의 합계를 반환한다.
- dim 으로 차원을 압축할 수 있다.
a = torch.tensor([[ 1, 2, 3],[ 4, 5, 6]]) #(2,3)
#dim = 0
b = torch.sum(a, dim = 0)
#dim = 1
c = torch.sum(a, dim = 1)
print(b)
print(c)
Output:
tensor([5, 7, 9])
tensor([ 6, 15])
여기서 dim을 tuple 형태로 넣을 수 있다.
tuple로 넣으면 차례대로 계산한다.
x = torch.rand(256, 10, 8)
print(torch.sum(x, dim=(2)).shape)
print(torch.sum(x, dim=(2,1)).shape)
Output:
torch.Size([256, 10])
torch.Size([256])
https://pytorch.org/docs/stable/generated/torch.sum.html
torch.sum — PyTorch 1.12 documentation
Shortcuts
pytorch.org
'AI > Pytorch' 카테고리의 다른 글
[Pytorch] torch.nn.RNN() _ RNN API (0) | 2022.10.20 |
---|---|
[Pytorch] nn.Embedding 임베딩 벡터 만들기 (0) | 2022.10.20 |
[Pytorch] torch.stack (Tensor 붙이기) (0) | 2022.10.18 |
[Pytorch] Pytorch 모델 불러오기(save, checkpoints, transfer learning) (0) | 2022.10.02 |
[Pytorch] Pytorch Datasets, Dataloaders (0) | 2022.10.02 |
Comments