我有点麻木
ndarray
大小
112 * 92
. 这基本上是一个灰度图像读取使用
cv2.imread
. 因为它的灰度所以它的最大值是
255
.
我正在尝试使用phe-paillier库加密此数组:
http://python-paillier.readthedocs.io/en/stable/usage.html#role-1
但当我运行
public_key.encrypt()
命令:
Traceback (most recent call last):
File "/usr/lib/python3.5/code.py", line 91, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "<input>", line 1, in <listcomp>
File "/usr/local/lib/python3.5/dist-packages/phe/paillier.py", line 169, in encrypt
encoding = EncodedNumber.encode(self, value, precision)
File "/usr/local/lib/python3.5/dist-packages/phe/encoding.py", line 176, in encode
% type(scalar))
TypeError: Don't know the precision of type <class 'numpy.uint8'>.
我试过了
float
和
int64
除了最后一行中的类更改,我一直得到相同的错误。
奇怪的是,如果我在他们的网站上运行手动输入列表的示例,它将毫无瑕疵地工作。我能理解的唯一区别就是我的numpy数组和它们的示例的类型。
当签入检查器时,其类型为
int
而我的是
uint8
.
secret_number_list = [3.141592653, 300, -4.6e-12]
type(secret_number_list)
<class 'list'>
type(secret_number_list[1])
<class 'int'>
然而,如果我对我的数组做同样的操作,我会得到:
type(image)
<class 'numpy.ndarray'>
type(image[0][0])
<class 'numpy.uint8'>
我试着把这个转换成
int
通过使用
image.astype(int)
但我有一个
英特64
在加密时给出相同错误的类型。
有没有一种方法可以将所有值转换为
int
而不是
英特64
?