How to compute element-wise entropy of an input tensor in PyTorch Last Updated : 21 Apr, 2022 Comments Improve Suggest changes Like Article Like Report 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 and returns a tensor with the element-wise entropy of the input tensor. if the element is zero, or negative then entropy is also zero, or negative infinity respectively. before moving further let's see the syntax of the given method. Syntax: torch.special.entr(tens) Parameters: tens: This is our input tensor. Returns: Returns the elements-wise entropy of an input tensor. Example 1: The following program is to understand how to compute the element-wise entropy of a 1D tensor. Python # import torch libraries import torch # creating a 1D tensor tens = torch.tensor([4, 5, 0, -5, -4]) # Display tensor print("\n\nInput Tensor: ", tens) # compute the element-wise entropy of # input tensor entr = torch.special.entr(tens) # Display result print("\n\nComputed Entropy: ", entr) Output: Example 2: The following program is to know how to compute the element-wise entropy of a 2D tensor. Python # import torch libraries import torch # creating a 2D tensor tens = torch.tensor([[1, 2, -3], [0, -3, 2], [-2, 0, -3]]) # Display tensor print("\n Input Tensor: \n", tens) # compute the element-wise entropy of # input tensor entr = torch.special.entr(tens) # Display result print("\n Computed Entropy: \n", entr) Output: Comment More infoAdvertise with us Next Article How to compute element-wise entropy of an input tensor in PyTorch M mukulsomukesh Follow Improve Article Tags : Python Python-PyTorch Practice Tags : python Similar Reads How to compute the element-wise angle of given input tensor in PyTorch? 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.angl 3 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 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 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 Like