Compared to the library version:
import numpy as np
np.linalg.inv([[1,2],[3,4]])
and this does handle the case where the determinant is 0 (by throwing an error about it being a singular matrix).