아래 내용은 pytorch 2.1.0 버전으로 작성됨.
0. 바로 사용하기
result = torch.mul(a, b)
a
: input data1
b
: input data2
1. 기본형
- torch 메서드로 사용
torch.mul(input, other, *, out=None) → Tensor
- torch.Tensor 메서드로 사용
torch_Tensor_1.mul(torch_Tensor_2) → Tensor
- 연산자 오버로딩
result = torch_Tensor_1 * torch_Tensor_2
- in-place 연산
torch.mul_(input_1, input_2)
2. 기능
- 요소별 곱셈(element-wise)를 연산하여 torch.Tensor로 반환해줌
- 특징
- Broadcasting
- In-place 연산 (
torch.mul_()
)
3. 파라미터
- 요소별 곱셈(element-wise)를 진행할 input data
other
- 요소별 곱셈을 진행할 other input data. 브로드캐스팅이 가능 하기 때문에 scalar 값도 넣을 수 있다.

ref