Perform Permute Operation in PyTorch

Shahid Akhtar Khan
Updated on 06-Dec-2021 11:03:59

3K+ Views

torch.permute() method is used to perform a permute operation on a PyTorch tensor. It returns a view of the input tensor with its dimension permuted. It doesn't make a copy of the original tensor.For example, a tensor with dimension [2, 3] can be permuted to [3, 2]. We can also permute a tensor with new dimension using Tensor.permute().Syntaxtorch.permute(input, dims)Parametersinput – PyTorch tensor.dims – Tuple of desired dimensions.StepsImport the torch library. Make sure you have it already installed.import torch Create a PyTorch tensor and print the tensor and the size of the tensor.t = torch.tensor([[1, 2], [3, 4], [5, 6]]) print("Tensor:", ... Read More

Perform Expand Operation in PyTorch

Shahid Akhtar Khan
Updated on 06-Dec-2021 10:59:35

3K+ Views

Tensor.expand() attribute is used to perform expand operation. It expands the Tensor to new dimensions along the singleton dimension.Expanding a tensor only creates a new view of the original tensor; it doesn't make a copy of the original tensor.If you set a particular dimension as -1, the tensor will not be expanded along this dimension.For example, if we have a tensor of size (3, 1), we can expand this tensor along the dimension of size 1.StepsTo expand a tensor, one could follow the steps given below −Import the torch library. Make sure you have already installed it.import torchDefine a tensor ... Read More

Create Tensors with Gradients in PyTorch

Shahid Akhtar Khan
Updated on 06-Dec-2021 10:54:45

5K+ Views

To create a tensor with gradients, we use an extra parameter "requires_grad = True" while creating a tensor.requires_grad is a flag that controls whether a tensor requires a gradient or not.Only floating point and complex dtype tensors can require gradients.If requires_grad is false, then the tensor is same as the tensor without the requires_grad parameter.Syntaxtorch.tensor(value, requires_grad = True)Parametersvalue – tensor data, user-defined or randomly generated.requires_grad – a flag, if True, the tensor is included in the gradient computation.OutputIt returns a tensor with requires_grad as True.StepsImport the required library. The required library is torch.Define a tensor with requires_grad = TrueDisplay the ... Read More

Find Element-wise Remainder in PyTorch

Shahid Akhtar Khan
Updated on 06-Dec-2021 10:49:37

320 Views

Element-wise remainder when a tensor is divided by other tensor is computed using the torch.remainder() method. We can also apply torch.fmod() to find the remainder.The difference between these two methods is that in torch.remainder(), when the sign of result is different than the sign of divisor, then the divisor is added to the result; whereas in torch.fmod(), it is not added.Syntaxtorch.remainder(input, other) torch.fmod(input, other)ParametersInput – It is a PyTorch tensor or scalar, the dividend.Other – It is also a PyTorch tensor or scalar, the divisor.OutputIt returns a tensor of element-wise remainder values.StepsImport the torch library.Define tensors, the dividend and the ... Read More

Compute Singular Value Decomposition (SVD) of a Matrix in PyTorch

Shahid Akhtar Khan
Updated on 06-Dec-2021 10:43:33

998 Views

torch.linalg.svd() computes the singular value decomposition (SVD) of a matrix or a batch of matrices. Singular value decomposition is represented as a named tuple (U, S, Vh).U and Vh are orthogonal for real matrix and unitary for input complex matrix.Vh is transpose of V when V is a real value and conjugate transpose when V is complex.S is always real valued even when the input is complex.SyntaxU, S, Vh = torch.linalg.svd(A, full_matrices=True)ParametersA – PyTorch tensor (matrix or batch of matrices).full_matrices – If True, the output is a full SVD, else a reduced SVD. Default is True.OutputIt returns a named tuple ... Read More

Perform In-Place Operations in PyTorch

Shahid Akhtar Khan
Updated on 06-Dec-2021 10:31:27

2K+ Views

In-place operations directly change the content of a tensor without making a copy of it. Since it does not create a copy of the input, it reduces the memory usage when dealing with high-dimensional data. An in-place operation helps to utilize less GPU memory.In PyTorch, in-place operations are always post-fixed with a "_", like add_(), mul_(), etc.StepsTo perform an in-place operation, one could follow the steps given below −Import the required library. The required library is torch.Define/create tensors on which in-place operation is to be performed.Perform both normal and in-place operations to see the clear difference between them.Display the tensors ... Read More

Relation Between Trigonometric and Exponential Fourier Series

Manish Kumar Saini
Updated on 03-Dec-2021 12:42:36

13K+ Views

Trigonometric Fourier SeriesA periodic function can be represented over a certain interval of time in terms of the linear combination of orthogonal functions. If these orthogonal functions are the trigonometric functions, then it is known as trigonometric Fourier series.Mathematically, the standard trigonometric Fourier series expansion of a periodic signal is, $$\mathrm{x(t)=a_{0}+ \sum_{n=1}^{\infty}a_{n}\:cos\:\omega_{0}nt+b_{n}\:sin\:\omega_{0}nt\:\:… (1)}$$Exponential Fourier SeriesA periodic function can be represented over a certain interval of time in terms of the linear combination of orthogonal functions, if these orthogonal functions are the exponential functions, then it is known as exponential Fourier series.Mathematically, the standard exponential Fourier series expansion for a periodic ... Read More

How to Treat Inflation in Investment Evaluation

Probir Banerjee
Updated on 03-Dec-2021 12:08:19

543 Views

Inflation is an important parameter in investments, as it erodes the value of money. It must be included in capital budgeting so that cash flows are appropriately included in the evaluation of an investment. In doing so, the inflation targets must be forecasted accurately over a considerably longer duration.Here are some considerations that must be made while creating inflation in an investment evaluation process.The forecasts must be spread over a periodInflation is an ever-existing truth nowadays. Investors face this reality day-in and day-out. They want to gain a return that is more than the inflation rates so that the value ... Read More

What is Free Cash Flow?

Probir Banerjee
Updated on 03-Dec-2021 12:04:17

488 Views

Free cash flow is the capital retained by a company after it has paid all its expenses, including building, rent, tax, payroll, inventory, etc. Companies may use the free cash flow for anything it sees fit.Free cash flow is a true measure of a company’s profitability.Businesses usually calculate free cash flow to take critical business decisions, such as whether to invest the money for expansion or to invest the money in ways to reduce the costs of operations.Investors use the free cash flow metric to check the frauds in accounting, as these measures are stringent and less manipulable than net ... Read More

What is Product Cannibalization

Probir Banerjee
Updated on 03-Dec-2021 11:48:12

1K+ Views

Product cannibalization is the process in which a new project or product eats away the cash flows earned by an already existing product. That means, when a new project or product is launched, it may take the cash flow away from an already running product or project. Business decisions must include the cannibalization effect into consideration because ignoring this may lead to huge losses sometimes.Capital budgeting decisions are taken keeping profitability and market share of products and they should include a holistic approach.A new product or project must not negatively impact an already available product or project which is running ... Read More

Advertisements