Files
Book4_Power-of-Matrix/Book4_Ch21_Python_Codes/Bk4_Ch21_01.py
2022-07-23 11:06:35 -04:00

27 lines
543 B
Python

###############
# Authored by Weisheng Jiang
# Book 4 | From Basic Arithmetic to Machine Learning
# Published and copyrighted by Tsinghua University Press
# Beijing, China, 2022
###############
# Bk4_Ch21_01.py
import numpy as np
def is_pos_def(A):
if np.array_equal(A, A.T):
try:
np.linalg.cholesky(A)
return True
except np.linalg.LinAlgError:
return False
else:
return False
A = np.array([[1,0],
[0,0]])
print(is_pos_def(A))