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.
Implement a function that computes both the determinant and trace of a square matrix. The determinant is a scalar value that can be computed from the elements of a square matrix and encodes certain properties of the matrix. The trace is simply the sum of the elements on the main diagonal. Return both values as a tuple.
matrix=[[2, 3], [1, 4]]
(5.0, 6.0)
The determinant of a 2x2 matrix is computed as ad−bc where the matrix is (acbd). Here: 2×4−3×1=8−3=5. The trace is the sum of diagonal elements: 2+4=6.