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 inverse of a 2x2 matrix. The inverse of a matrix A is another matrix A_inv such that A * A_inv = I (the identity matrix).
For a 2x2 matrix [[a, b], [c, d]], the inverse exists only if the determinant (ad - bc) is non-zero.
Return None if the matrix is not invertible (i.e., when the determinant equals zero).
matrix = [[4, 7], [2, 6]]
[[0.6, -0.7], [-0.2, 0.4]]
For matrix [[a, b], [c, d]] = [[4, 7], [2, 6]]: