mirror of
https://github.com/Visualize-ML/Book4_Power-of-Matrix.git
synced 2026-02-03 02:24:03 +08:00
27 lines
543 B
Python
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))
|