For loop issues for a Markov chain Monte Carlo

130 views Asked by At

So here is my next problem. I am trying to to loop through and find out how many of the entries in State_Space have a 1 as their 25th entry yet it keeps telling me that the answer is 0. Here is the code.

import random
import numpy

M=numpy.zeros((52),dtype=int)


z=0
State_Space=[]

for i in range(1,100500):
    x=random.randint(1,50)


    T=M.copy()
    if T[x]==1:
        T[x]=0
    if T[x]==0:
        T[x]=1


    if not any(numpy.array_equal(T, X) for X in State_Space):
        if T[x+1]==0 and T[x-1]==0:
            State_Space.append(T)
            if T[25]==1:
                z=z+1
            M=T


    else:
         if T[x+1]==0 and T[x-1]==0:
            M=T


print z
print len(State_Space)

Output:

0, 22

0

There are 0 answers