MoonNote

torch.sum( dim) 본문

Study/Python

torch.sum( dim)

Kisung Moon 2021. 9. 14. 21:25

torch.sum 에는 차원을 정해주는 argument가 있다.

dim=0 column 별로 더한 값이고

dim=1 은 row별로 더한 값을 출력한다.

import torch

a = torch.randn(2, 3)
>>>print(a)
>>>print(torch.sum(a, dim=0))
>>>print(torch.sum(a, dim=1))

tensor([[-0.2771,  0.4708,  0.7797],
        [ 2.8122, -1.0677,  1.7852]])
tensor([ 2.5351, -0.5969,  2.5649])
tensor([0.9734, 3.5298])

 

'Study > Python' 카테고리의 다른 글

주소  (0) 2021.09.09
EDA library 추천: pandas-profiling  (0) 2021.08.20
pandas: 특정 조건의 row를 drop하기  (0) 2021.07.17
pandas: 조건 일치하는 dataframe 출력  (0) 2021.07.16
파이썬(Python)에서 모든 조합 구하기  (0) 2021.07.14
Comments