Compute the inverse of a square, non-singular matrix A. Return None for non-square or singular matrices.
Matrix Inverse:
AA−1=A−1A=Iwhere I is the identity matrix and A−1 exists only if det(A)≠0.
A: 2D NumPy array, shape (n, n) - square matrix to invertInput: A = [[1, 2], [3, 4]]
Output: shape = (2, 2), A_inv ≈ [[-2, 1], [1.5, -0.5]]
Input: A = [[2.0]]
Output: shape = (1, 1), A_inv = [[0.5]]
Check for 2D and square matrix using A.ndim == 2 and A.shape[0] == A.shape[1].
Check if matrix is singular by computing np.linalg.det(A) and comparing with a small threshold like 1e-10.
None if singular or invalid)np.linalg.inv()Sign in to take notes on this problem
Accepts: array
Compute the inverse of a square, non-singular matrix A. Return None for non-square or singular matrices.
Matrix Inverse:
AA−1=A−1A=Iwhere I is the identity matrix and A−1 exists only if det(A)≠0.
A: 2D NumPy array, shape (n, n) - square matrix to invertInput: A = [[1, 2], [3, 4]]
Output: shape = (2, 2), A_inv ≈ [[-2, 1], [1.5, -0.5]]
Input: A = [[2.0]]
Output: shape = (1, 1), A_inv = [[0.5]]
Check for 2D and square matrix using A.ndim == 2 and A.shape[0] == A.shape[1].
Check if matrix is singular by computing np.linalg.det(A) and comparing with a small threshold like 1e-10.
None if singular or invalid)np.linalg.inv()Sign in to take notes on this problem
Accepts: array