Find out if matrix is positive definite with numpy

Zygimantas Gatelis picture Zygimantas Gatelis · Apr 28, 2013 · Viewed 46.5k times · Source

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 help.

Answer

Akavall picture Akavall · Apr 29, 2013

You can also check if all the eigenvalues of matrix are positive, if so the matrix is positive definite:

import numpy as np

def is_pos_def(x):
    return np.all(np.linalg.eigvals(x) > 0)