我需要一种有效的算法或已知方法来确定具有正特性场中的系数的矩阵A 的数学秩 。
例如,在5个元素的有限域中,我有以下矩阵:
import numpy A=[[2,3],[3,2]] print numpy.linalg.matrix_rank(A)该方法给出了2的结果,但在特征5中,该矩阵具有等级1,因为[2,3]+[3,2]=[0,0] 。
I need an efficient algorithm or a known way to determine the mathematical rank of a matrix A with coefficients in a field of positive characteristic.
For example, in the finite field of 5 elements I have the following matrix:
import numpy A=[[2,3],[3,2]] print numpy.linalg.matrix_rank(A)This method gives me the result of 2, but in characteristic 5 this matrix has rank 1 since [2,3]+[3,2]=[0,0].
最满意答案
Numpy没有内置的有限字段支持。 代码中的矩阵A被视为实数矩阵,因此具有等级2。
如果你真的需要使用Numpy支持有限字段,你必须自己定义自己的数据类型和算术运算,如下所示。 当然存在关于正确错误处理的问题(例如除以零)。
即使这样,也必须重写许多常用例程以支持您的字段数据类型。 例如,从numpy.linalg.matrix_rank文档中,例程使用奇异值分解(SVD),它没有为有限域定义,因此您必须自己编码排名算法。
至于算法本身,你可以尝试沿着这些线实现普通的高斯消除,但这可能是一个痛苦的问题,并且非常慢,所以你可能会更好地使用像Sage这样的其他工具/软件包。
Numpy doesn't have built-in support for finite fields. The matrix A in your code is treated as a matrix of real numbers, and hence has rank 2.
If you really need to support finite fields with Numpy, you'll have to define your own data type along with the arithmetic operations yourself, as shown here. There are of course the concerns about proper error handling (like divide by zero).
Even then, many common routines will have to be rewritten to support your field data types. For example, from the numpy.linalg.matrix_rank documentation, the routine uses Singular Value Decomposition (SVD), which is not well defined for finite fields, so you'll have to code the rank finding algorithm yourself.
As for the algorithm itself, you could try implementing plain old Gaussian Elimination along these lines, but this can be a pain in the neck and really slow, so you will likely be better off with other tools/packages like Sage.
更多推荐
发布评论