Blog Full Notice
back to main page

최대 1 분 소요

motivation: (torch.tensor).transpose() method에 대해서 이해해보자.

예를 들어서,

tensor1 = torch.rand(3,4)
tensor2 = torch.rand(3,4)

이런 tensor 2개가 있다고 하자.

torch.matmul(tensor1, tensor2.transpose(-1,-2))  # 이렇게 하면 tensor2의 마지막과 두번째 마지막 차원이 바뀐다.
torch.matmul(tensor1, tensor2.transpose(0,1))   # 위의 것과 같은 효과

이렇게 하면 행렬 곱셈이 잘 되게 된다.

A.transpose()가 A.permute(2,0,1) 과 다른 점은, permute가 더 일반적이라는 것이다. transpose method는 차원을 두개만 바꿀 수 있지만, permute는 자유롭게 변경시킬 수 있다는 점이 더 일반적이라고 말할 수 있는 것이다.

댓글남기기