Pytorch Torch Mul
# PyTorch torch.mul Function
* * *
[
**Parameters**:
* `input` (Tensor): The first input tensor.
* `other` (Tensor or float): The second input tensor or scalar.
* `out` (Tensor, optional): The output tensor.
**Return Value**:
* `torch.Tensor`: Returns the multiplied tensor.
* * *
## Usage Examples
### Example 1: Element-wise Tensor Multiplication
## Example
import torch
a = torch.tensor([1,2,3])
b = torch.tensor([4,5,6])
c = torch.mul(a, b)
print(c)
Output result:
tensor([ 4, 10, 18])
### Example 2: Multiply by Scalar
## Example
import torch
a = torch.tensor([1,2,3])
# Multiply by 2
b = torch.mul(a,2)
print(b)
# Can also use * operator
c = a * 2
print(c)
Output result:
tensor([2, 4, 6]) tensor([2, 4, 6])
* * *
[![Image 4: Pytorch torch Reference Manual]( Pytorch torch Reference Manual](
YouTip