How to compute the element-wise angle of given input tensor in PyTorch? Last Updated : 22 Apr, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we are going to see how to compute the element-wise angle of a given input tensor in PyTorch. torch.angle() method Pytorch is an open-source deep learning framework available with a Python and C++ interface. Pytorch resides inside the torch module. In PyTorch, we will use torch.angle() method to compute the element-wise angle, the input is passed in the form of a tensor in radians. To compute the angle in the degree we multiply the angle in radian by 180/NumPy.pi, before moving further let's see the syntax of the given method: Syntax: torch.angle(tens, *, out=None) Parameters: tens - This is our input tensor.out - This is our output tensor (optional). Returns: Returns the elements-wise angle of given tensor. Example 1: In this example, we will compute element-wise angles in radians of a given 1-D tensor. Python3 # Import the required libraries import torch # define a complex tensor input = torch.tensor([1 - 2j, 2 + 1j, 3 - 2j, -4 + 3j, -5 - 2j]) # print the above define tensor print("\n Input Tensor: ", input) # compute the elements-wise angle in radians ang = torch.angle(input) # print the computed elements-wise angle in radians print("\n Elements-wise angles in radian: ", ang) Output: Example 2: In this example, we will compute element-wise angles to convert the angle into a degree of the given 1-D tensor. Python3 # Import the required libraries import torch from numpy import pi # define a complex tensor input = torch.tensor([1 - 2j, 2 + 1j, 3 - 2j, -4 + 3j, -5 - 2j]) # print the above define tensor print("\n\nInput Tensor: ", input) # compute the elements-wise angle in radians ang = torch.angle(input) # convert the angle in degree deg = ang*180/pi # print the computed elements-wise angle in degree print("\nElements-wise angles in degree: ", deg) Output: Example 3: In this example, we will compute element-wise angles to convert the angle into a degree of the given 2-D tensor. Python3 # Import the required libraries import torch from numpy import pi # define a complex tensor input = torch.tensor([[1 - 2j, 2 + 3j, 3 - 3j], [4 + 3j, 5 - 4j, -6 + 2j], [-7 - 2j, 8 + 2j, 9 - 4j]]) # print the above define tensor print("\n Input Tensor:\n ", input) # compute the elements-wise angle in radians radians = torch.angle(input) # print the computed elements-wise angle in radians print("\n Elements-wise angles in radians:\n ", radians) # convert the angle in degree degree = radians * 180/pi # print the computed elements-wise angle in degree print("\n Elements-wise angles in degree:\n ", degree) Output: Comment More infoAdvertise with us Next Article How to compute the element-wise angle of given input tensor in PyTorch? mukulsomukesh Follow Improve Article Tags : Python Python-PyTorch Practice Tags : python Similar Reads How to compute element-wise entropy of an input tensor in PyTorch In this article, we are going to discuss how to compute the element-wise entropy of an input tensor in PyTorch, we can compute this by using torch.special.entr() method. torch.special.entr() method torch.special.entr() method computes the element-wise entropy, This method accepts a tensor as input a 2 min read How to compute element-wise remainder of given input tensor in PyTorch? In this article, we are going to see how to compute the element-wise remainder in PyTorch. we have two methods to compute element-wise reminders one is torch.remainder() and the other one is torch.fmod() let's go discuss both of them one by one. torch.remainder() method The PyTorch remainder() meth 3 min read How to Compute the Logistic Sigmoid Function of Tensor Elements in PyTorch In this article, we will see how to compute the logistic sigmoid function of Tensor Elements in PyTorch. The torch.special.expit() & torch.sigmoid() methods are logistic functions in a tensor. torch.sigmoid() is an alias of torch.special.expit() method.  So, these methods will take the torch ten 2 min read How To Sort The Elements of a Tensor in PyTorch? In this article, we are going to see how to sort the elements of a PyTorch Tensor in Python. To sort the elements of a PyTorch tensor, we use torch.sort() method.  We can sort the elements along with columns or rows when the tensor is 2-dimensional. Syntax: torch.sort(input, dim=- 1, descending=Fals 3 min read How to perform element-wise addition on tensors in PyTorch? In this article, we are going to see how to perform element-wise addition on tensors in PyTorch in Python. We can perform element-wise addition using torch.add() function. This function also allows us to perform addition on the same or different dimensions of tensors. If tensors are different in di 3 min read How to Get the Value of a Tensor in PyTorch When working with PyTorch, a powerful and flexible deep learning framework, you often need to access and manipulate the values stored within tensors. Tensors are the core data structures in PyTorch, representing multi-dimensional arrays that can store various types of data, including scalars, vector 5 min read How to Compute the Heaviside Step Function for Each Element in Input in PyTorch? In this article, we are going to cover how to compute the Heaviside step function for each element in input in PyTorch using Python. We can compute this with the help of torch.heaviside() method. torch.heaviside() method The torch.heaviside() method is used to compute the Heaviside step function for 2 min read How to perform element-wise division on tensors in PyTorch? In this article, we will understand how to perform element-wise division of two tensors in PyTorch. To perform the element-wise division of tensors, we can apply the torch.div() method. It takes two tensors (dividend and divisor) as the inputs and returns a new tensor with the element-wise division 3 min read How to find the transpose of a tensor in PyTorch? In this article, we are going to discuss how to find the transpose of the tensor in PyTorch. The transpose is obtained by changing the rows to columns and columns to rows. we can transpose a tensor by using transpose() method. the below syntax is used to find the transpose of the tensor. Syntax: tor 2 min read How to perform element-wise multiplication on tensors in PyTorch? In this article, we are going to see how to perform element-wise multiplication on tensors in PyTorch in Python. We can perform element-wise addition using torch.mul() method. This function also allows us to perform multiplication on the same or different dimensions of tensors. If tensors are diffe 3 min read Like