[Tensor]#7 dimension of sum

Clay Ryu's sound lab·2023년 7월 14일
0

Framework

목록 보기
17/49

https://pytorch.org/docs/stable/generated/torch.sum.html
dim (int or tuple of ints, optional) – the dimension or dimensions to --reduce--. If None, all dimensions are reduced.

import numpy as np

_pianoroll.shape, np.sum(_pianoroll, axis=0).shape
# outputs
((161, 128), (128,))
_pianoroll.shape, np.sum(_pianoroll, axis=1).shape
# outputs
((161, 128), (161,))
import torch

b = torch.ones(4 * 5 * 6).view(4, 5, 6)
torch.sum(b, dim=(1,2))
# outputs
tensor([30., 30., 30., 30.])
torch.sum(b, dim=(2,1))
# outputs
tensor([30., 30., 30., 30.])
profile
chords & code // harmony with structure

0개의 댓글