
Python/numpy & Pytorch
[Pytorch] tensor 합치기는 방법 cat(), stack()
'+' 연산자 list list에서는 '+' 연산자를 쓰면 list가 합쳐진다. x = [1,2] x2 = [3,4] x+x2 [1, 2, 3, 4] Tensor tensor는 합쳐지지 않고 각 원소마다 더해진다. 이는 같은 차원끼리 더하거나 한 차원이 1일 때만 가능함 x = torch.randint(0, 10,(3,1)) x2 = torch.randint(0, 10,(3,1)) x3 = torch.randint(0, 10,(1,1)) x, x2, x+x2, x+x3 tensor([[4], [2], [1]]) tensor([[2], [1], [2]]) tensor([[6], [3], [3]]) tensor([[5], [3], [2]]) x = torch.randint(0, 10,(3,1)) x2 = t..