I am attempting to loop through a matrix, called lattice
, randomly using the randrange
function. My matrix is an 8x8 and prints fine. However when I attempt to randomly loop through each element of this matrix I am getting the error
'TypeError: 'int' object is not iterable'
Due the upper limit of the range, len(mymatrix)
. I'm unsure as to why this is.
for R1 in randrange(0, (len(lattice)):
for R2 in randrange(0, len(lattice)):
H = -j*lattice[R1,R2]*(lattice[R1+1,R2],lattice[R1-1,R2], lattice[R1,R2+1],lattice[R1,R2-1]) +h*lattice[R1,R2]
H_flip = -j*-1*mymatrix[R1,R2]*(lattice[R1+1,R2],lattice[R1-1,R2], lattice[R1,R2+1],lattice[R1,R2-1]) +h*lattice[R1,R2]
print lattice[R1,R2]
I have not used randrange
in a loop before, is it perhaps that it can't be used the same way range is used? I've also tried to set the range as:
for R1 in randrange(0, len(lattice)-1)
I thought maybe the length was one too long but to no avail.
random.randrange
returns and compare it to whatrange
returns. – Michael Butscher