有人知道我为什么会收到此语法错误吗?
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:换行符后出现意外字符
答案 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