我正在使用 gf256 库进行 galois 场数学运算,并将它放在一个 numpy 矩阵中。尽管使用它调用np.linalg.inv()
时,它会引发错误。
以上是总结,下面是详细内容:
import numpy as np
from gf256 import GF256 as gf
npgf = np.vectorize(gf)
arr = np.identity(4, np.uint8) * 10
gfarr = npgf(arr)
毕竟,gfarr
看起来像这样
array([[GF256(0b00001010), GF256(0b00000000), GF256(0b00000000),
GF256(0b00000000)],
[GF256(0b00000000), GF256(0b00001010), GF256(0b00000000),
GF256(0b00000000)],
[GF256(0b00000000), GF256(0b00000000), GF256(0b00001010),
GF256(0b00000000)],
[GF256(0b00000000), GF256(0b00000000), GF256(0b00000000),
GF256(0b00001010)]], dtype=object)
并np.linalg.inv(gfarr)
抛出此错误
Traceback (most recent call last):
File "<pyshell#152>", line 1, in <module>
np.linalg.inv(gfarr)
File "[python3.6]\lib\site-packages\numpy\linalg\linalg.py", line 528, in inv
ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
TypeError: No loop matching the specified signature and casting
was found for ufunc inv
矩阵绝对是可逆的,GF256 类支持所有常用运算符。是否可以使用 numpy 进行这项工作?