我想写一个函数,其中给定两个整数“n”和“p”,它生成所有n阶可逆矩阵,其中元素来自{0,1,…,p-1}。 我有以下代码:
import itertools
import numpy as np
def invertible_matrices(n, p):
invertibleMatrices = set()
# generates all the possible matrices
x = [y for y in range(p)]
a = [j for j in itertools.product(x, repeat=n)]
b = {k for k in itertools.product(a, repeat=n)}
for each in b:
if np.linalg.det(each) != 0:
invertibleMatrices.add(each)
return invertibleMatrices
对于n=2
和p=2
它可以正常工作,但是对于n=2
和p=3
我得到50
,而答案是48
。
任何帮助都将不胜感激
如果你熟悉群论,我想找到GL(n, p)(有限域上p元素的一般线性群)的所有元素
使用inspect_matrix()进行调试,获取_Inversible_matrix()使用集合理解来确定所有可逆矩阵,获取_Determinate_1_matrix()来获取行列式为1的矩阵:
返回:
我想你想要的是行列式模p(它是GL(n,p)中的行列式,也就是有限域上的p元素)
注:+1是为了避免小数值误差的缠绕
相关问题 更多 >
编程相关推荐