接收连续字符语法错误

时间:2018-10-13 23:34:55

标签: python-3.x encryption syntax

有人知道我为什么会收到此语法错误吗?

    def softmax(self,x):
    return 1/(1+np.exp(-x))

def encrypt(self,pubkey,scaling_factor=1000):
    if(not self.encrypted):
        self.pubkey = pubkey
        self.scaling_factor = float(scaling_factor)
        self.encrypted_weights = list()

        for weight in model.weights:
            self.encrypted_weights.append(self.pubkey.encrypt(\\ 
            int(min(weight,self.maxweight) * self.scaling_factor)))
        self.encrypted = True            
        self.weights = None

    return self

File "<ipython-input-33-9ca6863eb9a3>", line 11
self.encrypted_weights.append(self.pubkey.encrypt(\\
                                                     ^

SyntaxError:换行符后出现意外字符

1 个答案:

答案 0 :(得分:0)

好吧,我想您忘记了将关键字self放在model.weight之前,并从np导入numpy。试试这个:

import np
def softmax(self,x):
    return 1/(1+np.exp(-x))

def encrypt(self,pubkey,scaling_factor=1000):
    if(not self.encrypted):
        self.pubkey = pubkey
        self.scaling_factor = float(scaling_factor)
        self.encrypted_weights = list()

    for weight in self.model.weights:
        self.encrypted_weights.append(self.pubkey.encrypt(int(min(weight, self.maxweight) * self.scaling_factor)))
    self.encrypted = True            
    self.weights = None

return self