Browse and solve 1,200+ machine learning coding challenges on Deep-ML. Filter by difficulty (beginner, intermediate, advanced) and category (linear algebra, machine learning, deep learning, NLP, computer vision). Write Python solutions in the browser and get instant feedback against test cases.
Write a Python function that calculates the eigenvalues of a 2x2 matrix. The function should return a list containing the eigenvalues, sort values from highest to lowest.
matrix = [[2, 1], [1, 2]]
[3.0, 1.0]
The eigenvalues of the matrix are calculated using the characteristic equation of the matrix, which for a 2x2 matrix is λ2−trace(A)λ+det(A)=0, where λ are the eigenvalues.