Python : 'int' Object is not iterable Random function

Asked

Viewed 340 times

2

I’m having this mistake when I run the code.

If I define pos=(algum numero qualquer) code runs normally ,but if I use this error function.

'int' Object is not iterable in line 20 at first.

Where am I missing? in the Deposit function I’m sending y.sub=matrix of zeros.

import numpy as np
import random

def Deposito(x): 

    for i in range(16):
        pos=randint(0,15)
        D=(pos+1)%16;
        E=(pos+15)%16;
        h=0

        while h<30:

            if (x[h,D]==1 and x[h,pos]==0):
                x[h,pos]=1 
                break        
            elif (x[h,E]==1 and x[h,pos]==0):
                x=[h,pos]=1 
                break 
            elif (x[h,pos]==1):
                x[h-1,pos]=1 
                break
            h=h+1
            if h==29:
                x[h,pos]=1


class Amostra: 

    substrato=np.zeros((30,16))
    sub=substrato   

    y=Amostra()

1 answer

1


It’s not the reason for the mistake but here it should be:

pos = random.randint(0,15)

But I think the mistake is here:

# ...
elif (x[h,E]==1 and x[h,pos]==0):
    x=[h,pos]=1 
    break
# ...

That should be x[h, pos] = 1, nay?

  • Thank you very much . Total lack of attention even .

  • Now the error message makes sense until.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.