是否有一种方法可以用python在域F2(即加法和乘法模2-二进制场)上求解线性方程组?有一段时间我一直在寻找有用的包裹,但没有想出任何办法.
谢谢,
发布于 2021-12-12 19:38:17
我创建了一个package 伽罗瓦,它将NumPy数组扩展到有限域。它还支持NumPy线性代数例程在np.linalg中。
下面是一个求解线性系统Ax = b的x在GF(2)中的例子。
In [1]: import numpy as np
In [2]: import galois
In [3]: GF = galois.GF(2)
In [4]: A = GF.Random((4,4)); A
Out[4]:
GF([[0, 1, 0, 0],
[0, 0, 1, 1],
[0, 0, 0, 1],
[1, 1, 0, 0]], order=2)
In [5]: x_truth = GF([1,0,1,1]); x_truth
Out[5]: GF([1, 0, 1, 1], order=2)
In [6]: b = A @ x_truth; b
Out[6]: GF([0, 0, 1, 1], order=2)
# Solve Ax = b for x
In [7]: x = np.linalg.solve(A, b); x
Out[7]: GF([1, 0, 1, 1], order=2)
# Verify that x is x_truth
In [8]: np.array_equal(x, x_truth)
Out[8]: Truehttps://stackoverflow.com/questions/62190107
复制相似问题