Found 33676 Articles for Programming

Python – scipy.linalg.tanm()

Syed Abeed
Updated on 24-Dec-2021 10:12:31

229 Views

The tanm() function of scipy.linalg package is used to compute the tangent of an input matrix. This routine uses expm to compute the matrix exponentials.Syntaxscipy.linalg.tanm(x)where x is the input array or a square matrix. It returns the matrix tangent of x.Example 1Let us consider the following example −# Import the required libraries from scipy import linalg import numpy as np # Define the input array x = np.array([[69 , 12] , [94 , 28]]) print("Input array: ", x) # Calculate the Tangent a = linalg.tanm(x) # Display the Tangent of matrix print("Tangent of X: ", a)OutputIt will ... Read More

Python – scipy.linalg.cosm

Syed Abeed
Updated on 24-Dec-2021 10:10:45

220 Views

The cosm() function of scipy.linalg package is used to compute the cosine of an input matrix. This routine uses expm to compute the matrix exponentials.Syntaxscipy.linalg.cosm(x)where x is the input array.Example 1Let us consider the following example −# Import the required libraries from scipy import linalg import numpy as np # Define the input array q = np.array([[121 , 10] , [77 , 36]]) print("Array Input :", q) # Calculate the Cosine r = linalg.cosm(q) # Display the Cosine of matrix print("Cosine of Q: ", r)OutputThe above program will generate the following output − Array Input : ... Read More

Python – scipy.linalg.sinm()

Syed Abeed
Updated on 24-Dec-2021 10:08:49

233 Views

The sinm() function scipy.linalg package is used to compute the sine of an input matrix. This routine uses expm to compute the matrix exponentials.Syntaxscipy.linalg.sinm(x)where x is the inputer array.Example 1Let us consider the following example −# Import the required libraries from scipy from scipy import linalg import numpy as np # Define the input array X = np.array([[110, 12], [79, 23]]) print("Input Matrix, X:", X) # Calculate the Sine of the matrix n = linalg.sinm(X) # Display the Sine print("Sine of X: ", n)OutputIt will generate the following output − Input Matrix, X: [[110 12] ... Read More

Python – scipy.linalg.expm

Syed Abeed
Updated on 24-Dec-2021 10:07:01

2K+ Views

The expm() function of scipy.linalg package is used to compute the matrix exponential using Padé approximation. A Padé approximant is the "best" approximation of a function by a rational function of given order. Under this technique, the approximant's power series agrees with the power series of the function it is approximating.Syntaxscipy.linalg.expm(x)where x is the input matrix to be exponentiated.Example 1Let us consider the following example −# Import the required libraries from scipy import linalg import numpy as np # Define the input array e = np.array([[100 , 5] , [78 , 36]]) print("Input Array :", e) # Calculate ... Read More

Python – scipy.linalg.sqrtm

Syed Abeed
Updated on 22-Dec-2021 10:07:13

1K+ Views

The sqrtm() function of scipy.linalg package can be used to find the square root of an input matrix.Syntaxscipy.linalg.sqrtm(x)Example 1Let us consider the following example −# Importing the required libraries from scipy from scipy import linalg import numpy as np # Define the input array x = np.array([[14 , 2] , [89 , 33]]) print("Input array:", x) # Calculate the square root r = linalg.sqrtm(x) # Display the square root print("Square Root of x: ", r)OutputIt will generate the following output −Input array: [[14 2] [89 33]] Square Root of x: [[3.43430132 0.22262855] [9.90697038 5.54927253]]Example 2Let us take ... Read More

Python – scipy.linalg.norm

Syed Abeed
Updated on 22-Dec-2021 10:05:34

585 Views

The norm() function of the scipy.linalg package is used to return one of eight different matrix norms or one of an infinite number of vector norms.Syntaxscipy.linalg.norm(x)Where x is an input array or a square matrix.Example 1Let us consider the following example −# Importing the required libraries from scipy from scipy import linalg import numpy as np # Define the input array x = np.array([7 , 4]) print("Input array:", x) # Calculate the L2 norm r = linalg.norm(x) # Calculate the L1 norm s = linalg.norm(x, 3) # Display the norm values print("Norm Value of r :", ... Read More

Python – scipy.linalg.inv

Syed Abeed
Updated on 22-Dec-2021 10:02:40

401 Views

The scipy.linalg package contains a of different functionalities that are used for Linear Algebra. One of them is the inv() function, which is used to find the inverse of a square matrix.Syntaxscipy.linalg.inv(x)Where x is a square matrix.Example 1Let us consider the following example −# Import the required libraries from scipy import linalg import numpy as np # defines the array a = np.array([[5, 3], [6, 4]]) print("Input matrix :", a) # Finding the inverse of a square matrix x = linalg.inv(a) print(" Inverse of Square Matrix A :", x)OutputThe above program will generate the following output −Input matrix ... Read More

Python – scipy.linalg.det

Syed Abeed
Updated on 22-Dec-2021 09:59:56

321 Views

The scipy.linalg package contains a set of different functionalities that are used for Linear Algebra. One of them is the det() function. This function is used to find the determinant of a two-dimensional matrix.Syntaxscipy.linalg.det(x)Where x is a square matrix.Example 1Let us consider the following example −# Importing the required libraries from scipy import linalg import numpy as np # Initialize the matrix A A = np.array([[8, 5], [3, 4]]) print("Input Matrix :", A) # Find the determinant of matrix X x = linalg.det(A) print("Determinant Value of A:", x)OutputIt will generate the following output −Input Matrix : [[8 5] ... Read More

Python – scipy.special.logsumexp

Syed Abeed
Updated on 22-Dec-2021 09:54:51

2K+ Views

The scipy.special package contains a set of different functionalities that are used for mathematical physics. One of them is the logsumexp() function. This function is used to compute the log of the sum of exponentials of input elements. Let us take a couple of examples and see how to use this function.Syntaxscipy.special.logsumexp(x)where, x is the input value.Example 1Let us consider the following example −# Import logsumexp from scipy.special from scipy.special import logsumexp import numpy as np # Input array a = np.arange(10) print("Input Array:", a) # logsum() function res = logsumexp(a) print("logsumexp of a:", res)OutputIt will produce the ... Read More

How to check if an object is a PyTorch Tensor?

Shahid Akhtar Khan
Updated on 06-Dec-2021 12:44:53

8K+ Views

To check if an object is a tensor or not, we can use the torch.is_tensor() method. It returns True if the input is a tensor; False otherwise.Syntaxtorch.is_tensor(input)Parametersinput – The object to be checked, if it is a tensor or not .OutputIt returns True if the input is a tensor; else False.StepsImport the required library. The required library is torch.Define a tensor or other object.Check if the created object is a tensor or not using torch.is_tensor(input).Display the result.Example 1# import the required library import torch # create an object x x = torch.rand(4) print(x) # check if the above ... Read More

Advertisements