How to do a nested loop Jupyter Notebook Python

1.3k Views Asked by At

I am starting to work with Jupyter Notebook and I have no idea how to do a nested loop, tried everything I could think of. What I want to do is:

I=(0,1,2,3,4)
R=(0,1,2,3,4)
y= m.addVars(n,5, name="y", vtype=GRB.BINARY)
yy= m.addVars(n,5*n, name="yy", vtype=GRB.BINARY)

if (y[i,r]+y[j,r]==2): yy[i,j+5*r]=1 for i in I for j in I for r in R

If both y variables are 1, i want yy to be 1 aswell, 0 in all other cases.

Thanks in advance

1

There are 1 best solutions below

2
On

Try the following,

if y[i,r]+y[j,r] == 2:
    for i in I:
        for j in I:
            for r in R:
                yy[i,j+5*r]=1
else:
    yy[i,j+5*r]=0

I haven't tried as I am not able to get your m.addVars. If I am not wrong this is something to do with filtering of an image?^_^