Math Operations ontensir
There are three ways to perform every math operations to a tensor
#defining a tensors:
tensor_A=torch.tensor(5,2,6,1)
tensor_B=torch.tensor(2,4,2,4)
ADD :
Using short hand
tensor_A+tensor_B
tensor([7,6,8,5])
Using long-hand
torch.add(tensor_A,tensor_B)
Using Variable Name
tensor_A.add(tensor_B)
SUBTRACT :
Using short hand
tensor_A-tensor_B
tensor([3,-2,4,-3])
Using long-hand
torch.sub(tensor_A,tensor_B)
Using Variable Name
tensor_A.sub(tensor_B)
MULTIPLE :
Using short hand
tensor_A*tensor_B
tensor([10,8,12,4])
Using long-hand
torch.mul(tensor_A,tensor_B)
Using Variable Name
tensor_A.mul(tensor_B)
DIVISION :
Using short hand
tensor_A/tensor_B
tensor([2.0000,0.5000,3.0000,0.2500])
Using long-hand
torch.div(tensor_A,tensor_B)
Using Variable Name
tensor_A.div(tensor_B)
MODULE/REMINDER :
Using short hand
tensor_A%tensor_B
tensor([1,0,0,0])
Using long-hand
torch.reminder(tensor_A,tensor_B)
Using Variable Name
tensor_A.reminder(tensor_B)
POWER/EXPONENT:
Using short hand
tensor_A**tensor_B
tensor([25,16,36,1])
Using long-hand
torch.pow(tensor_A,tensor_B)
Using Variable Name
tensor_A.pow(tensor_B)
Assigning a tensor Value:
There are two ways :
Using underscore
tensor_A.add_(tensor_B)
Using equal
tensor_A=tensor_A+tensor_B