# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Cholesky Decomposition

import numpy as np
import scipy
import scipy.linalg

# Create Random Matrix

n=5

P=np.random.randn(n,n)
print(P)

# Make a covariance matrix

P=P @ P.T
print(P)

# Cholesky Decomposition with scipy, note the transpose operator - scipy returns upper-triangular matrix

L=scipy.linalg.cholesky(P).T
print(L)

# Check Result

print(P-L @ L.T)

# Cholesky Decomposition with numpy, returning lower-triangular matrix

nL = np.linalg.cholesky(P)
print (nL)

print(L-nL)



StarcoderdataJupyterScriptsDedupFiltered