def _inv22_vectorized(M):
 assert (M.ndim == 3)
 assert (M.shape[(-2):] == (2, 2))
 M_inv = np.empty_like(M)
 delta_inv = np.reciprocal(((M[:, 0, 0] * M[:, 1, 1]) - (M[:, 0, 1] * M[:, 1, 0])))
 M_inv[:, 0, 0] = (M[:, 1, 1] * delta_inv)
 M_inv[:, 0, 1] = ((- M[:, 0, 1]) * delta_inv)
 M_inv[:, 1, 0] = ((- M[:, 1, 0]) * delta_inv)
 M_inv[:, 1, 1] = (M[:, 0, 0] * delta_inv)
 return M_inv

def _inv22_vectorized ( M ) : assert ( M . ndim == 3 ) assert ( M . shape [ ( - 2 ) : ] == ( 2 , 2 ) ) M_inv = np . empty_like ( M ) delta_inv = np . reciprocal ( ( ( M [ : , 0 , 0 ] * M [ : , 1 , 1 ] ) - ( M [ : , 0 , 1 ] * M [ : , 1 , 0 ] ) ) ) M_inv [ : , 0 , 0 ] = ( M [ : , 1 , 1 ] * delta_inv ) M_inv [ : , 0 , 1 ] = ( ( - M [ : , 0 , 1 ] ) * delta_inv ) M_inv [ : , 1 , 0 ] = ( ( - M [ : , 1 , 0 ] ) * delta_inv ) M_inv [ : , 1 , 1 ] = ( M [ : , 0 , 0 ] * delta_inv ) return M_inv
inversion of arrays of matrices .