Datasets:

License:
File size: 938 Bytes
76cb30c
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
import numpy as np
from numpy import zeros, ndarray, array, sum, dot, maximum, tensordot
from numpy.linalg import inv, norm, eig
def inverse(qp_jacobis: ndarray, qp_jacobi_dets: ndarray) -> ndarray:
    qp_jacobi_invs = []
    for A, det_A in zip(qp_jacobis, qp_jacobi_dets):
        if A.shape == (2, 2):
            qp_jacobi_invs.append(array([[A[1][1], -A[0][1]], [-A[1][0], A[0][0]]]) / det_A)
        elif A.shape == (3, 3):
            qp_jacobi_invs.append(array([[(A[1][1] * A[2][2] - A[1][2] * A[2][1]), (A[0][2] * A[2][1] - A[0][1] * A[2][2]), (A[0][1] * A[1][2] - A[0][2] * A[1][1])], [(A[1][2] * A[2][0] - A[1][0] * A[2][2]), (A[0][0] * A[2][2] - A[0][2] * A[2][0]), (A[0][2] * A[1][0] - A[0][0] * A[1][2])], [(A[1][0] * A[2][1] - A[1][1] * A[2][0]), (A[0][1] * A[2][0] - A[0][0] * A[2][1]), (A[0][0] * A[1][1] - A[0][1] * A[1][0])]]) / det_A)
        else:
            return inv(qp_jacobis)
    return array(qp_jacobi_invs)