Return the Cholesky decomposition in Linear Algebra in Python

PythonNumpyServer Side ProgrammingProgramming

To return the Cholesky decomposition, use the numpy.linalg.cholesky() method. Return the Cholesky decomposition, L * L.H, of the square matrix a, where L is lower-triangular and .H is the conjugate transpose operator. The a must be Hermitian and positive-definite. No checking is performed to verify whether a is Hermitian or not. In addition, only the lower-triangular and diagonal elements of a are used. Only L is actually returned.

Then parameter a, is the Hermitian (symmetric if all elements are real), positive-definite input matrix. The method returns the Upper or lower-triangular Cholesky factor of a. Returns a matrix object if a is a matrix object.

Steps

At first, import the required libraries -

import numpy as np

Creating a 2D numpy array using the numpy.array() method −

arr = np.array([[1,-2j],[2j,5]])

Display the array −

print("Our Array...\n",arr)

Check the Dimensions −

print("\nDimensions of our Array...\n",arr.ndim)

Get the Datatype −

print("\nDatatype of our Array object...\n",arr.dtype)

Get the Shape −

print("\nShape of our Array object...\n",arr.shape)

To return the Cholesky decomposition, use the numpy.linalg.cholesky() method −

print("\nCholesky decomposition in Linear Algebra...\n",np.linalg.cholesky(arr))

Example

import numpy as np

# Creating a 2D numpy array using the numpy.array() method
arr = np.array([[1,-2j],[2j,5]])

# Display the array
print("Our Array...\n",arr)

# Check the Dimensions
print("\nDimensions of our Array...\n",arr.ndim)

# Get the Datatype
print("\nDatatype of our Array object...\n",arr.dtype)

# Get the Shape
print("\nShape of our Array object...\n",arr.shape)

# To return the Cholesky decomposition, use the numpy.linalg.cholesky() method.
print("\nCholesky decomposition in Linear Algebra...\n",np.linalg.cholesky(arr))

Output

Our Array...
[[ 1.+0.j -0.-2.j]
[ 0.+2.j 5.+0.j]]

Dimensions of our Array...
2

Datatype of our Array object...
complex128

Shape of our Array object...
(2, 2)

Cholesky decomposition in Linear Algebra...
[[1.+0.j 0.+0.j]
[0.+2.j 1.+0.j]]
raja
Updated on 24-Feb-2022 12:59:28

Advertisements