【问题标题】:TypeError: only size-1 arrays can be converted to Python scalars for encrypted dataTypeError:只有 size-1 的数组可以转换为 Python 标量以用于加密数据
【发布时间】:2019-08-07 06:35:24
【问题描述】:

我正在尝试加密此数据集Wholesales customer,已删除前两列(通道和区域)。 加密脚本工作正常,因为我能够生成用于加密的公钥。但是,我认为问题在于嵌套的 for 循环行。任何帮助,将不胜感激。

from Paillier_CRT.gmpy2mod import *
import numpy as np
import pandas as pd


priv, pub = generate_keypair(128)
n = pub.n
print("The public key is:", n)


def to_encrypt(public, data_matrix):
    data_encrypted = encrypt(public, data_matrix)
    return data_encrypted


def load_data():
    raw_data = pd.read_csv('wholesales1.csv')
    dtset = raw_data.drop(['Channel'], axis=1)
    new_dtset = dtset.drop(['Region'], axis=1)
    converted_data = new_dtset.values
    data_to_encrypt = []

    for row in converted_data:
        for elem in row:
            data_to_encrypt = to_encrypt(pub, int(converted_data))
            return data_to_encrypt


working_data = load_data()
print("The encrypted data is: ", working_data)

错误信息:

TypeError: only size-1 arrays can be converted to Python scalars

【问题讨论】:

    标签: python arrays numpy scalar


    【解决方案1】:

    此错误通常意味着您在预期数组的位置使用标量值。

    代替

    data_to_encrypt = to_encrypt(pub, int(converted_data))
    

    你可以试试

    data_to_encrypt = to_encrypt(pub, converted_data.astype(int))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2021-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多