我正在制作一个MLP并将我最后的隐藏层连接到输出。
class connection:
def __init__(self):
self.value = 0
self.weight = 0
self.network_output_index = 0
def connect(self,**network_instance**):
**network_instance**.output_array[self.network_output_index] = self.value * self.weight
class network:
def __init__(self):
self.output_array = [0,0,0,0]
blah blah python blah;
如何调用network_instance
的属性output_array
?
答案 0 :(得分:1)
修复缩进问题后,这似乎没有问题:
class connection:
def __init__(self):
self.value = 0
self.weight = 0
self.network_output_index = 0
def connect(self, network_instance):
network_instance.output_array[self.network_output_index] = self.value * self.weight
class network:
def __init__(self):
self.output_array = [0,0,0,0]
c = connection()
c.value = 5
c.weight = 2
n = network()
c.connect(n)
print(n.output_array)
[10, 0, 0, 0]