def is_semi_positive(matrix):
"""Check whether a matrix is positive semidefinite.
Args:
matrix: (array(array[complex]))
Returns:
bool: True if the matrix is positive semidefinite, False otherwise
"""
##################
# YOUR CODE HERE #
##################
eigenvalues = np.linalg.eigvals(matrix)
return np.all(eigenvalues >= 0)
matrix_1 = [[3/4,1/4],[1/4,1/4]]
matrix_2 = [[0,1/4],[1/4,1/4]]
print("Is matrix [[3/4,1/4],[1/4,1/4]] positive semidefinite?")
print(is_semi_positive(matrix_1))
print("Is matrix [[0,1/4],[1/4,1/4]] positive semidefinite?")
print(is_semi_positive(matrix_2))
I am attaching the snippet of error messages
Error: the output of your function isn't the right type.
How ever if I run this code in Google colab I am getting output as
True
Is matrix [[0,1/4],[1/4,1/4]] positive semidefinite?
False```