0

I am trying to use the flood fill algorithm to fill in one of the two colors of this curve, which is defined with red being 1 and blue being zero. However, when I try to run my code, it says that the syntax for the line if m[i][j]=1: is incorrect. Any advice on how to debug this? Thanks. In this code m is the matrix I am working in and i and j are my xy variables

from pylab import *
m=zeroes((100,100))

for i in range(100):
    for j in range(100):
        m[i,j]=sin(i+j+0.1*i*j+0.1*j*j)+cos(i-j+0.2*i*i)

n=m.copy()
n[n>0]=1
n[n<0]=0
imshow(n)

def floodfill (m,i,j):
    if m[i][j]=1: 
       m[i][j]=0

        if i>0:
            floodfill(matrix,i-1,j)
        if i < len(m[y]) - 1:
            floodfill(m, i+1, j)
        if j>0:   
            floodfill(m, i, j-1)

            floodfill(m, i, j-1)
Blair
  • 6,623
  • 1
  • 36
  • 42
Bmm
  • 57
  • 1
  • 4

2 Answers2

2

You didn't post the exact error, but I can tell you that this is incorrect:

m[i,j]=sin(i+j+0.1*i*j+0.1*j*j)+cos(i-j+0.2*i*i)

m[i,j] is incorrect. i,j is a tuple, but list indices (the thing inside the m[] brackets) can only be integers

touch my body
  • 1,634
  • 22
  • 36
2

Values are to be compared for equality using == operator rather than a single = which is used for assignment expressions. So you should replace if m[i][j]=1: with if m[i][j] == 1.

And BTW, it did say "Syntax Error", so you should check the syntax of the line highlighted. That's your hint for debugging.

Shubham
  • 2,847
  • 4
  • 24
  • 37