擅长:python、mysql、java
<p>可能不是最好的解决方案,但只是我的2c。如果您希望另一个神经元的树突也被更新,您可以这样声明连接:</p>
<pre><code>axonConns = [(n1.dendrites, 0), (n2.dendrites, 1), (n3.dendrites, 2)]
</code></pre>
<p>您需要传递树突列表本身,并通过索引定义连接中要考虑的树突。然后更改<code>fire</code>方法以考虑索引:</p>
<pre><code>def fire(self):
self.outputPotential = self.voltsOut
self.firing = self.on
print("Neuron is firing!")
for dendrites, index in self.axonConnections:
dendrites[index] = self.outputPotential
</code></pre>
<p>编辑:</p>
<p>来证明为什么OP的答案不足以更新<code>fire()</code>之外的神经元</p>
<pre><code>In [1]: x = [1, 2, 3]
...:
...: def foo(val):
...: potential = 100
...: for i in range(len(val)):
...: val[i] = potential
...: return val
...:
...: print(x)
...: print(foo([x[0], x[1], x[2]]))
...: print(x)
...:
[1, 2, 3]
[100, 100, 100]
[1, 2, 3]
</code></pre>