How to Apply Rectified Linear Unit Function Element-Wise in PyTorch? Last Updated : 02 Jun, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we are going to see How to Apply Rectified Linear Unit Function Element-Wise in PyTorch in Python. We can Rectify Linear Unit Function Element-Wise by using torch.nn.ReLU() method. torch.nn.ReLU() method In PyTorch, torch.nn.ReLu() method replaces all the negative values with 0 and all the non-negative left unchanged. The values of the tensor must be real only. we can also do this operation in-place by using inplace=True as a Parameter. before moving further let's see the syntax of the given method. Syntax: torch.nn.ReLU(inplace=False) Parameters: inplace: This parameter is use when we want to do this operation in-place. Default value of inplace is False. Example 1: The following program is to understand how to compute the Rectified Linear Unit Function Element-Wise. Python # Import the required library import torch import torch.nn as nn # define a tensor input = torch.tensor([[-1., 0., 2., 0.], [3., 4., -5., 0.], [6., -9., -10., 11.], [0., 13., 14., -15.]]) print(" Original Tensor: ", input) # Apply Rectified Linear Unit Function # Element-Wise Rel = torch.nn.ReLU() Output = Rel(input) # display result print(" Output Tensor: ", Output) Output: Example 2: The following program is to understand how to Apply Rectified Linear Unit Function with inplace=True. Python # Import the required library import torch import torch.nn as nn # define a tensor input = torch.tensor([[-2., 3., -6., 2.], [3., -6., 5., 0.], [6., -3., 0., -11.], [13., -13., 14., 15.]]) print(" Original Tensor: ", input) # Apply Rectified Linear Unit Function # Element-Wise Do this operation # in-place Rel = torch.nn.ReLU(inplace=True) Output = Rel(input) # display result print(" Output Tensor: ", Output) Output: Comment More infoAdvertise with us Next Article How to Apply Rectified Linear Unit Function Element-Wise in PyTorch? mukulsomukesh Follow Improve Article Tags : Python Python-PyTorch Practice Tags : python Similar Reads 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 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 perform element-wise subtraction on tensors in PyTorch? In this article, we are going to understand how to perform element-wise subtraction on tensors in PyTorch in Python. We can perform element-wise subtraction using torch.sub() method. torch.sub() method allows us to perform subtraction on the same or different dimensions of tensors. It takes two tens 3 min read 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 Apply torch.inverse() Function of PyTorch to Every Sample in the Batch PyTorch is a deep learning framework that provides a variety of functions to perform different operations on tensors. One such function is torch.inverse(), which can be used to compute the inverse of a square matrix. Sometimes we may have a batch of matrices, where each matrix represents some data t 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 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 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 How to create a custom Loss Function in PyTorch? Choosing the appropriate loss function is crucial in deep learning. It serves as a guide for directing the optimization process of neural networks while they are being trained. Although PyTorch offers many pre-defined loss functions, there are cases where regular loss functions are not enough. In th 3 min read Like