Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
Learning Pytorch for Mathematical computation
Commute the n-dimentional matrix (tensors)
Pytorch: An tool with easy to use API for higher-dimention math computaion.
- torch.clamp()
- torch.sigmoid()
- torch.std()
- torch.std_mean()
- torch.unique()
# Import torch and other required modules
#!conda install -y pytorch -c pytorch
import torch
tourch.clamp(input_tensor,min_value,max_value,output_tensor)
This function helps in clamping the matrix's values in the given range(min,max).
### tensor representing the data(sweets): sweet seasonality(True/False), sweet current demand (in tons), sweet price (INR/kg)
t = torch.Tensor([[True, 20, 600],
[False, 15, 360],
[True, 50, 960],
[False, 55, 1660],
[True, 35, 600]])
## validate the tensor
t
tensor([[1.0000e+00, 2.0000e+01, 6.0000e+02],
[0.0000e+00, 1.5000e+01, 3.6000e+02],
[1.0000e+00, 5.0000e+01, 9.6000e+02],
[0.0000e+00, 5.5000e+01, 1.6600e+03],
[1.0000e+00, 3.5000e+01, 6.0000e+02]])