Server Side Programming Articles - Page 687 of 2650

How to compute the inverse hyperbolic sine in PyTorch?

Shahid Akhtar Khan
Updated on 27-Jan-2022 07:20:09

203 Views

The torch.asinh() method computes the inverse hyperbolic sine of each element of the input tensor. It supports both real and complex-valued inputs. It supports any dimension of the input tensor.Syntaxtorch.asinh(input)where input is the input tensor.OutputIt returns a tensor inverse hyperbolic sine of each element.StepsTo compute the inverse hyperbolic sine of each element in the input tensor, you could follow the steps given below −Import the required library. In all the following examples, the required Python library is torch. Make sure you have already installed it.import torchCreate a torch tensor and print it.input = torch.randn(3, 4) print("Input Tensor:", input)Compute the inverse ... Read More

torch.rsqrt() Method in Python PyTorch

Shahid Akhtar Khan
Updated on 27-Jan-2022 07:12:49

441 Views

The torch.rsqrt() method computes the reciprocal of square-root of each element of the input tensor. It supports both real and complex-valued inputs. If an element in the input tensor is zero, then the corresponding element in the output tensor is NaN.Syntaxtorch.rsqrt(input)Parametersinput – Input tensorOutputIt returns a tensor with reciprocal of square-root.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 torch tensor and print it.input = torch.randn(3, 4) print("Input Tensor:", input)Compute the reciprocal of the square-root of each element in the input tensor using torch.rsqrt(input). Here ... Read More

How to compute the element-wise angle of the given input tensor in PyTorch?

Shahid Akhtar Khan
Updated on 27-Jan-2022 07:08:23

589 Views

To compute the elementwise angle of the given input tensor, we apply torch.angle(). It takes an input tensor and returns a tensor with angle in radian computed element wise. To convert the angles into the degree we multiply the angle in radian by 180/np.pi. It supports both real and complex-valued tensors.Syntaxtorch.angle(input)StepsTo compute the elementwise angle, you could follow the steps given below −Import the required library. In all the following examples, the required Python library is torch. Make sure you have already installed it.import torchDefine torch tensors and print them.input = torch.tensor([1 + 1j, -1 -4j, 3-2j])Compute torch.angle(input). It is ... Read More

How to compute bitwise AND, OR and NOT of given input tensors in PyTorch?

Shahid Akhtar Khan
Updated on 27-Jan-2022 07:02:10

485 Views

To compute bitwise AND of given input tensors we apply torch.bitwise_and(). The input tensors must be of integral or Boolean types. For bool tensors, it computes the logical AND.To compute bitwise NOT of a given input tensor we apply torch.bitwise_not() method. The input tensors must be of integral or Boolean types. For bool tensors, it computes the logical OR.To compute the bitwise NOT of a given input tensor we apply torch.bitwise_not() method. The input tensor must be of integral or Boolean types. For bool tensors, it computes the logical NOT.Syntaxtorch.bitwise_and(input1, input2) torch.bitwise_or(input1, input2) torch.bitwise_not(input)StepsImport the required library. In all the ... Read More

How to compute the inverse cosine and inverse hyperbolic cosine in PyTorch?

Shahid Akhtar Khan
Updated on 27-Jan-2022 06:53:56

264 Views

The torch.acos() method computes the inverse cosine of each element of an input tensor. It supports both real and complex-valued inputs. It supports any dimension of the input tensor. The elements of the input tensor must be in the range [-1, 1], as the inverse cosine function has its domain as [-1, 1].The torch.acosh() method computes the inverse hyperbolic cosine of each element of the input tensor. It also supports both real and complex-valued inputs of any dimension. The elements of the input tensor must be any number greater or equal to 1, as the inverse cosine function has its ... Read More

How to create a tensor whose elements are sampled from a Poisson distribution in PyTorch?

Shahid Akhtar Khan
Updated on 27-Jan-2022 06:48:25

467 Views

To create a tensor whose elements are sampled from a Poisson distribution, we apply the torch.poisson() method. This method takes a tensor whose elements are rate parameters as input tensor. It returns a tensor whose elements are sampled from a Poisson distribution with the rate parameter.Syntaxtorch.poisson(rates)where the parameter rates is a torch tensor of rate parameters. Rate parameters are used to sample elements from a Poisson distribution.StepsWe could use the following steps to create a tensor whose elements are sampled from a Poisson distribution −Import the required library. In all the following examples, the required Python library is torch. Make ... Read More

How to compute the Heaviside step function for each element in input in PyTorch?

Shahid Akhtar Khan
Updated on 27-Jan-2022 06:32:30

417 Views

To compute the Heaviside step function for each element in the input tensor, we use the torch.heaviside() method. It accepts two parameters − input and values. It returns a new tensor with a computed heaviside step function.The value of heaviside function is the same as values if input=0. The value of heaviside is zero if input is less than zero. The value of heaviside is 1 if input is greater than zero. It accepts torch tensors of any dimension. It is also called the unit step function.Syntaxtorch.heaviside(input, values)StepsWe could use the following steps to compute the Heaviside step function −Import ... Read More

How to draw binary random numbers (0 or 1) from a Bernoulli distribution in PyTorch?

Shahid Akhtar Khan
Updated on 27-Jan-2022 06:27:18

1K+ Views

To draw binary random numbers (0 or 1) from a Bernoulli distribution, we apply the torch.bernoulli() method. The input to this method is a torch tensor containing the probabilities of drawing 1. These probabilities are used to draw binary random numbers (0 or 1).As the input tensor contains the probabilities, all the elements should be in the range [0, 1]. It returns a tensor whose elements (0 or 1) are randomly selected from a Bernoulli distribution with the input probabilities.Syntaxtorch.bernoulli(input)where, the parameter input is a torch tensor containing the probabilities of drawing 1. These probabilities are used to draw the ... Read More

torch.normal() Method in Python PyTorch

Shahid Akhtar Khan
Updated on 27-Jan-2022 06:10:04

2K+ Views

To create a tensor of random numbers drawn from separate normal distributions whose mean and std are given, we apply the torch.normal() method. This method takes two input parameters − mean and std.mean is a tensor with the mean of each output element’s normal distribution, andstd is a tensor with the standard deviation of each output element’s normal distribution.It returns a tensor of random numbers drawn from separate normal distributions whose mean and standard deviation are mean and std.Syntaxtorch.normal(mean, std)StepsWe could use the following steps to create a tensor of random numbers drawn from separate normal distributions −Import the required ... Read More

torch.polar() Method in Python PyTorch

Shahid Akhtar Khan
Updated on 27-Jan-2022 06:03:29

543 Views

With given absolute values and angles, we can construct a complex number in PyTorch using torch.polar() method. The absolute value and angles must be float or double. Both the absolute value and the angle must be of the same type.If abs is a float, then angle must also be float.If the inputs are torch.float32, then the constructed complex tensor must be torch.complex64.If the inputs are torch.float64, then the complex tensor must be torch.complex128.Syntaxtorch.polar(abs, angle)Parametersabs – The absolute length of the complex tensor.angle – The angle of the complex tensor.StepsWe could use the following steps to construct a complex tensor with ... Read More

Advertisements