How to compute the sine of elements of a tensor in PyTorch?
Published December 30, 2021The torch.sin() method is used to compute tensor element sines. This function produces a new tensor containing the sine values of the original input tensor's members. It accepts a tensor as an input argument and returns a tensor as an output parameter.
How to calculate the sine of tensor elements
Simply follow the steps below to calculate the sine of tensor elements in PyTorch.
· Step 1: Import the necessary library. Torch is the Python library that is needed in all of the following Python examples. Check to see if you've already installed it.
· Step 2: Create a tensor and print it.
· Step 3: Determine torch. Sin (input). It accepts a tensor as an input parameter and returns a new tensor with the sine values of the input's members.
· Step 4: Print the tensor with the sine values of the original input tensor's elements.
Example
T = torch.Tensor([1.3,4.32,4.4,5.3,4.5]) sine_T = torch.sin(T)
|
Output
The code above will display the following output
tensor([1.3000, 4.3200, 4.4000, 5.3000, 4.5000]) tensor([ 0.9636, -0.9240, -0.9516, -0.8323, -0.9775])
|
Article Contributed By :
|
|
|
|
669 Views |