## Python – scipy.linalg.sqrtm Updated on 22-Dec-2021 10:07:13
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 Updated on 22-Dec-2021 10:05:34
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 Updated on 22-Dec-2021 10:02:40
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 Updated on 22-Dec-2021 09:59:56
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 Updated on 22-Dec-2021 09:54:51
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

## Which linear function of SciPy is used to solve Toeplitz matrix using Levinson Recursion? Updated on 24-Nov-2021 12:13:08
The linear function named scipy.linalg.solve_toeplitz is used to solve the Toeplitz matrix equation. The form of this function is as follows −scipy.linalg.solve_toeplitz(c_or_cr, b, check_finite=True)This linear function will solve the equation Tx = b for x where T is the Toeplitz matrix.ParametersBelow are given the parameters of the function scipy.linalg.solve_toeplitz()c_or_cr− array_like or tuple of (array_like, array_like)This parameter is the vector c or tuple of arrays (c, r). Despite the actual shape of c, it will always be converted to a one-dimensional array. If r is not given, the assumption made is r = conjugate(c). Below are given two cases −    ... Read More

## How to solve triangular matrix equations using Python SciPy? Updated on 24-Nov-2021 14:37:03
The linear function named scipy.linalg.solveh_triangular is used to solve the banded matrix equation. In the below given example we will be solving the triangular system ax = b where −$$\mathrm{a} = \begin{bmatrix} 3 & 0 & 0 & 0\ 2 & 1 & 0 & 0\ 1 &0 &1 &0 \ 1& 1& 1& 1 \end{bmatrix};\; \mathrm{b} =\begin{bmatrix} 1\ 2\ 1\ 2 \end{bmatrix}$$Examplefrom scipy.linalg import solve_triangular import numpy as np a = np.array([[3, 0, 0, 0], [2, 1, 0, 0], [1, 0, 1, 0], [1, 1, 1, 1]]) b = np.array([1, 2, 1, 2]) x = solve_triangular(a, b, lower=True) print (x)Outputarray([ 0.33333333, 1.33333333, 0.66666667, -0.33333333])

## Which linear function of SciPy is used to solve triangular matrix equations? Updated on 24-Nov-2021 12:05:15
The linear function named scipy.linalg.solve_triangular is used to solve the triangular matrix e8quation. The form of this function is as follows −scipy.linalg.solve_triangular(a, b, trans=0, lower=False, unit_diagonal=False, overwrite_b=False, debug=None, check_finite=True)This linear function will solve the equation ax = b for x where a is a triangular matrix.P ParametersBelow are given the parameters of the function scipy.linalg.solve_triangular() −a− (M, M) array_likeThis parameter represents the triangular matrix.b− (M, ) or (M, N)array_likeThis parameter represents the right-hand side matrix in the equation ax = b.lower− bool, optionalBy using this parameter, we will be able to use only the data that is contained in the ... Read More

## How to solve a circulant matrix equation using Python SciPy? Updated on 24-Nov-2021 11:53:49
The linear function named scipy.linalg.solveh_banded is used to solve the banded matrix equation. In the below given example we will be solving the circulant system Cx = b −Examplefrom scipy.linalg import solve_circulant, solve, circulant, lstsq import numpy as np c = np.array([2, 2, 4]) b = np.array([1, 2, 3]) solve_circulant(c, b)Output array([ 0.75, -0.25, 0.25])ExampleLet’s see a singular example, it will raise an LinAlgError −from scipy.linalg import solve_circulant, solve, circulant, lstsq import numpy as np c = np.array([1, 1, 0, 0]) b = np.array([1, 2, 3, 4]) solve_circulant(c, b)Output -------------------------------------------------------------------------- LinAlgError Traceback (most recent call last) in ... Read More

## Which linear function of SciPy is used to solve the circulant matrix equation? Updated on 24-Nov-2021 11:50:36
The linear function named scipy.linalg.solve_circulant is used to solve the circulant matrix equation. The form of this function is as follows −scipy.linalg.solve_circulant(c, b, singular=’raise’, tol=None, caxis=-1, baxis=0, outaxis=0)This linear function will solve the equation Cx = b for x where C is a Circulant matrix associated with the vector c.The circulant matrix equation is solved by doing division in Fourier space as follows −x = ifft(fft(b) / fft(c))Here fft is the fast Fourier transform and ifft is the inverse fast Fourier transform.ParametersBelow are given the parameters of the function scipy.linalg.solve_circulant() −c− array_likeThis parameter represents the coefficient of the circulant matrix.b− ... Read More