计算未成年人的矩阵行列式!

发布于 2024-10-31 01:33:34 字数 53 浏览 5 评论 0原文

我想用Python计算未成年人的矩阵行列式,也许使用scipy或其他一些包。 有什么建议吗?

i want to caluculate Matrix determinants of minors in Python, maybe using scipy or some other package.
any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

╭⌒浅淡时光〆 2024-11-07 01:33:34

Numpy/SciPy 将完成这一切。

Numpy/SciPy will do all this.

清引 2024-11-07 01:33:34

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

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

该函数输出

np.linalg.det(M)

To create the minor matrix you could use the function

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

With this output

np.linalg.det(M)
那请放手 2024-11-07 01:33:34

要创建矩阵的主次要行列式并对每个行列式进行微积分,您需要执行以下操作:

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]]

To create the principal minor determinants of a matrix and make the calculus for each one determinant, you would want to do this:

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]]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文