To compute the determinant of a square matrix, we could apply torch.linalg.det() method. It returns a new tensor with computed determinant. It accepts a square matrix, a batch of square matrices and also batches of square matrices. It supports matrix of float, double, cfloat, and cdouble data types.We could also apply torch.det() method to compute the determinant. It is an alias of the torch.linalg.det() method.Syntaxtorch.linalg.det(mat) torch.det(mat)Where mat is a square matrix or batch/s of square matrices. A matrix is a 2D torch tensor.StepsWe could use the following steps to compute determinant of a square matrix −Import the required library. In ... Read More
To compute the logistic function of elements of a tensor, we use torch.special.expit() method. It returns a new tensor with computed logistic function element-wise. It accepts torch tensor of any dimension. We could also apply torch.sigmoid() method to compute the logistic function of elements of the tensor. It is an alias of the torch.special.expit() method.Syntaxtorch.special.expit(input) torch.sigmoid(input)Where input is a torch tensor of any dimension.StepsWe could use the following steps to compute logistic sigmoid function of a tensor element-wise −Import the required library. In all the following examples, the required Python library is torch. Make sure you have already installed it.import ... Read More
torch.linalg.qr() computes the QR decomposition of a matrix or a batch of matrices. It accepts matrix and batch of matrices of float, double, cfloat and cdouble data types.It returns a named tuple (Q, R). Q is orthogonal when the matrix is real valued and unitary when matrix is complex valued. And R is an upper triangular matrix.Syntax(Q, R) = torch.linalg.qr(mat, mode='reduced')ParametersMat – Square matrix or a batch of square matrices.mode – It decides mode of QR decomposition. It is set to one of three modes, 'reduced', 'complete', and 'r'. Default is set to 'reduced'. It's an optional parameter.StepsImport the required library. In ... Read More
To compute the error function of a tensor, we use the torch.special.erf() method. It returns a new tensor with computed error function. It accepts torch tensor of any dimension. It is also known as Gauss error functionStepsWe could use the following steps to compute the error function of a tensor element-wise −Import the required library. In all the following examples, the required Python library is torch. Make sure you have already installed it.import torchDefine a torch tensor. Here we define a 2D tensor of random numbers.tensor = torch.randn(2, 3, 3)Compute the error function of the above-defined tensor using torch.special.erf(tensor). Optionally ... Read More
torch.linalg.eig() computes the Eigen value decomposition of a square matrix or a batch of square matrices. It accepts matrix and batch of matrices of float, double, cfloat and cdouble data types. It returns a named tuple (eigenvalues, eigenvectors). The eigenvalues and eigenvectors are always complex valued. The eigenvectors are given by columns of eigenvectors.Syntax(eigenvalues, eigenvectors) = torch.linalg.eig(A)Where A is a square matrix or a batch of square matrices. It returns a named tuple (eigenvalues, eigenvectors).StepsImport the required library. In all the following examples, the required Python library is torch. Make sure you have already installed it.import torchCreate a square matrix ... Read More
The RandomInvert() transform inverts the colors of an image randomly with a given probability. The torchvision.transforms module provides many important transforms that can be used to perform different types of manipulations on the image data.RandomInvert() accepts both PIL and tensor images or batch of tensor images. A tensor image is a PyTorch Tensor with shape [3, H, W], where H is the image height and W is the image width. A batch of tensor images is also a torch tensor with [B, 3, H, W] where B is the number of images in the batch.Syntaxtorchvision.transforms.RandomInvert(p)(img)It returns a randomly color inverted ... Read More
RandomRotation() rotates an image by a random angle. The chosen random angle is from a given range of angles in degree. RandomRotation() is one of the many important transforms provided by the torchvision.transforms module. RandomRotation() transform accepts both PIL and tensor images.A tensor image is a Torch tensor with shape [C, H, W], where C is the number of channels, H is the image height, and W is the image width. If the image is neither a PIL image nor a tensor image, then we first convert it to a tensor image and then apply the transform.Syntaxtorchvision.transforms.RandomRotation(degree)(img)Where degree is the ... Read More
To pad an image on all sides, we can apply Pad() transform provided by the torchvision.transforms module. This module contains many important transformations that can be used to perform different types of manipulations on the image data.Pad() transformation accepts both PIL and tensor images or a batch of tensor images. A tensor image is a torch Tensor with shape [C, H, W], where C is the number of channels, H is the image height, and W is the image width.A batch of tensor images is also a torch tensor with shape [B, C, H, W]. B is the number of ... Read More
To compute the element-wise entropy of an input tensor, we use torch.special.entr() method. It returns a new tensor with entropy computed element-wise.If the element of tensor is negative, the entropy is negative infinity.If the element of the tensor is a zero, the entropy is zero.The entropy for a positive number element is computed as the negative value of the element multiplied by its natural logarithm. It accepts torch tensor of any dimension.StepsWe could use the following steps to compute the entropy on a tensor element-wise −Import the required library. In all the following examples, the required Python library is torch. Make ... Read More
The RandomErasing() transform randomly selects a rectangular region in an input image and erases its pixels. The torchvision.transforms module provides many important transforms that can be used to perform different types of manipulations on the image data. RandomErasing() transformation accepts only tensor images of any size. A tensor image is a torch tensor.As this transform supports only tensor image, the PIL images should be first converted to a torch tensor. And after applying the RandomErasing() transform, we convert torch tensor image to PIL image.StepsWe could use the following steps to randomly select a rectangular region in an input image and ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP