+ 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?

24th Mar 2020, 3:35 PM
محمد بهمنی
محمد بهمنی - avatar
12 ответов
+ 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.
24th Mar 2020, 5:43 PM
Russ
Russ - avatar
+ 6
Please link your complete code here. This makes it much more easier to help. Thank’s!
24th Mar 2020, 5:00 PM
Lothar
Lothar - avatar
+ 1
What is 'W'? Is it a 2D array?
24th Mar 2020, 5:02 PM
Russ
Russ - avatar
+ 1
Yes it's 2D
24th Mar 2020, 5:03 PM
محمد بهمنی
محمد بهمنی - avatar
+ 1
...and how is it meant to look before and after these lines?
24th Mar 2020, 5:11 PM
Russ
Russ - avatar
+ 1
is: for i in range(8): W[i].insert(i, 0) ...enough?
24th Mar 2020, 5:18 PM
Russ
Russ - avatar
+ 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
24th Mar 2020, 5:27 PM
محمد بهمنی
محمد بهمنی - avatar
+ 1
It's my code
24th Mar 2020, 5:27 PM
محمد بهمنی
محمد بهمنی - avatar
+ 1
But the real result isn't like this
24th Mar 2020, 5:28 PM
محمد بهمنی
محمد بهمنی - avatar
+ 1
Thank you very much.
24th Mar 2020, 6:03 PM
محمد بهمنی
محمد بهمنی - avatar
+ 1
While I < 8 : w[I].insert(I,0)
26th Mar 2020, 2:21 PM
Kishan Sudani
Kishan Sudani - avatar