计算未成年人的矩阵决定因素!

时间:2011-04-05 19:08:09

标签: python math matrix scipy scientific-computing

我想在Python中计算未成年人的矩阵决定因素,可能使用scipy或其他一些包。 有什么建议吗?

3 个答案:

答案 0 :(得分:2)

Numpy / SciPy会做这一切。

答案 1 :(得分:0)

要创建次要矩阵,您可以使用函数

def minor(M, i, j):
    M = np.delete(M, i, 0)
    M = np.delete(M, j, 1)
    return M

使用此输出

np.linalg.det(M)

答案 2 :(得分:0)

要创建矩阵的主要次要行列式并为每个行列式进行演算,您需要这样做:

import numpy as np

# procedure for creating principal minor determinants
def minor(M, size):
    # size can be 2x2, 3x3, 4x4 etc.
    theMinor = []

    for i in range(size):
        clearList = []
        for j in range(size):
            clearList.append(M[i][j])

        theMinor.append(clearList)

    return theMinor


# procedure to handle the principal minor
def handleMinorPrincipals(A, n):
    # A is a square Matrix
    # n is number or rows and cols for A

    if n == 0:
        return None
    if n == 1:
        return A[0][0]

    # size 1x1 is calculated
    # we now look for other minors
    for i in range(1, n):
        # get the minor determinant
        minDet = minor(A, i + 1)

        # check if determinant is greater than 0
        if np.linalg.det(minDet) > 0:
            # do smth
        else:
            # smth else

    return
Example:

[[8. 8. 0. 0. 0.]
 [6. 6. 3. 0. 0.]
 [0. 4. 4. 4. 0.]
 [0. 0. 2. 2. 2.]
 [0. 0. 0. 2. 2.]]

size = 1 -> Minor is 

[8]

size = 2 -> Minor is

[[8. 8.]
[6. 6.]]

size = 3 -> Minor is

[[8. 8. 0.]
[6. 6. 3.]
[0. 4. 4]]