简体   繁体   English

如何在Python中找到矩阵的行列式?

[英]How to find determinant of a matrix in Python?

The task at hand is to find the determinant of A matrix and find the error in detResult variable.手头的任务是找到A矩阵的行列式并找到detResult变量中的误差。

import numpy as np

A = np.array([(1,2),(3,4)])
detResult = A[1,1]*A[2,2]-A[1,2]*A[1,2]  #does not compile

There are 2 ways in which I could get the answer, but I don't see any small/negligible typo in the given version of detResult .有两种方法可以获得答案,但在给定版本的detResult我没有看到任何小的/可以忽略的错字。

1st way:第一种方式:

det1 = A[0,0:1] * A[1,1:2] - A[0,1:] * A[1,0:1]

2nd way:方式二:

det2 = A[0][0] * A[1][1] - A[0][1] * A[1][0]

You may use the inbuilt function in Numpy, numpy.linalg.det() .您可以使用 Numpy 中的内置函数numpy.linalg.det() More information can be found on the Numpy Docs: https://numpy.org/doc/stable/reference/generated/numpy.linalg.det.html更多信息可以在 Numpy Docs 上找到: https ://numpy.org/doc/stable/reference/generated/numpy.linalg.det.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM