+ 1
Who can help me?
W[0].insert(0, 0) W[1].insert(1, 0) W[2].insert(2, 0) to 7 Do you know a way by for or while loops to Write these codes in a easier way?
11 Answers
+ 5
def hopfield1(spin) :
Num=len(spin)
W=[[0]*Num for i in range(0,Num)]
...
W had 4 copies of the same list (listac). Solved now.
+ 6
Please link your complete code here. This makes it much more easier to help. Thank’s!
+ 1
What is 'W'? Is it a 2D array?
+ 1
Yes it's 2D
+ 1
...and how is it meant to look before and after these lines?
+ 1
is:
for i in range(8):
W[i].insert(i, 0)
...enough?
+ 1
def hopfield1(spin) :
Num=len(spin)
listac=[0 for i in range(0,Num) ]
W=[listac for i in range(0,Num)]
for i in range(0,Num):
for j in range(0,Num):
if i!=j:
W[i][j] =spin[i] *spin[j]
else:
W[i][j] =0
print(W)
return
hopfield1([-1,1,-1,1] )
I wanted this result
W=[[0,-1,1,-1],[-1,0,-1,1],[1,-1,0,-1],[-1,1,-1,0]]
EX.
W[2][3]=spin[2]*spin[3]
W[2][2]=0
+ 1
It's my code
+ 1
But the real result isn't like this
+ 1
Thank you very much.
+ 1
While I < 8 : w[I].insert(I,0)