Find out if matrix is positive definite with numpy

后端 未结 8 2134
慢半拍i
慢半拍i 2020-12-23 13:40

I need to find out if matrix is positive definite. My matrix is numpy matrix. I was expecting to find any related method in numpy library, but no success. I appreciate any

8条回答
  •  有刺的猬
    2020-12-23 13:54

    For Not symmetric Matrix you can use the Principal Minor Test :

    def isPD(Y):
      row = X.shape [0]
      i = 0
      j = 0
      for i in range(row+1) : 
        Step = Y[:i,:j]
        j+=1
        i+=1
        det = np.linalg.det(Step)
        if det > 0 : 
            continue 
        else :
            return ("Not Positive Definite, Test Principal minor failed")
    
      return ("Positive Definite")
    

提交回复
热议问题