Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6939193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:35:26+00:00 2026-05-27T12:35:26+00:00

A couple of days ago I asked for help with the floodfill function and

  • 0

A couple of days ago I asked for help with the floodfill function and the stackoverflow community was very helpful in pointing me to the bugs in my function (I am new to python and programming). The function will search adjoining elements in an array and look for ones with values within 0.05 of each other much like a floodfill algorithm does. Now when I run it, it seems to work for small arrays but doesn’t for big arrays

    import numpy
    import time
    def floodcount (x,y,arraycopy,value,count=0):
        #print 'x= ', x
        nrows = len(arraycopy) -1        #rows of the image
        ncols = len(arraycopy[0])-1       #columns of the image
        if x < 0 or y < 0 or x > nrows or y > ncols:
            return count

        diff = arraycopy[x][y] - value
        print '[',x,y,']','-',value, ' = ', diff
        # the base case, finding a diff more than 0.5 or less than 0 is like finding a boundary
        if (diff < 0.00) or (diff > 0.5): 
            return count

        count = count +1

        arraycopy[x][y] = -5 # so we do no calculate this pixel again
       #print "[",x,",",y,"]"

        count = floodcount (x-1,y,arraycopy,value,count)
        count = floodcount (x,y+1,arraycopy,value,count)
        count = floodcount (x+1,y,arraycopy,value,count)
        count = floodcount (x,y-1,arraycopy,value,count)
        count = floodcount (x-1,y-1,arraycopy,value,count)
        count = floodcount (x+1,y+1,arraycopy,value,count)
        count = floodcount (x+1,y-1,arraycopy,value,count)
        count = floodcount (x-1,y+1,arraycopy,value,count)


        return count



    array =numpy.zeros([31,31]) # fails for anything bigger than 31x31

    arraycopy = [x[:] for x in array]

    thresholdMin, thresholdMax, thresholdStep = 0,0,0.5
    thresholdRange = numpy.arange( thresholdMin, thresholdMax+thresholdStep,  thresholdStep )

    for x in range(len(arraycopy)):
        for y in range(len(arraycopy[0])):
            tempstorage= []
            value = float(arraycopy [x][y])
            if value != -5 and value in thresholdRange:
                print value,x,y
                matches = floodcount(x,y,arraycopy,value)

                    tempstorage.append(matches)
                    maxarea = max(tempstorage)
                    found.append([value,maxarea])

The code works for arrays smaller than 31×31 but not bigger. If I assign a bigger array it errors something like this

Output

  Traceback (most recent call last):
  File "C:\Users\Geek\Desktop\Light stuff\floodcount.py", line 73, in <module>
    matches = floodcount(x,y,arraycopy,value)
  File "C:\Users\Geek\Desktop\Light stuff\floodcount.py", line 22, in floodcount
    count = floodcount (x,y+1,arraycopy,value,count)
  File "C:\Users\Geek\Desktop\Light stuff\floodcount.py", line 22, in floodcount
    count = floodcount (x,y+1,arraycopy,value,count)
  File "C:\Users\Geek\Desktop\Light stuff\floodcount.py", line 22, in floodcount
    count = floodcount (x,y+1,arraycopy,value,count)
  File "C:\Users\Geek\Desktop\Light stuff\floodcount.py", line 22, in floodcount
    count = floodcount (x,y+1,arraycopy,value,count)
  File "C:\Users\Geek\Desktop\Light stuff\floodcount.py", line 22, in floodcount
    count = floodcount (x,y+1,arraycopy,value,count)
  File "C:\Users\Geek\Desktop\Light stuff\floodcount.py", line 22, in floodcount
    count = floodcount (x,y+1,arraycopy,value,count)
  File "C:\Users\Geek\Desktop\Light stuff\floodcount.py", line 22, in floodcount
    count = floodcount (x,y+1,arraycopy,value,count)
  File "C:\Users\Geek\Desktop\Light stuff\floodcount.py", line 22, in floodcount
    count = floodcount (x,y+1,arraycopy,value,count)
  File "C:\Users\Geek\Desktop\Light stuff\floodcount.py", line 22, in floodcount
    count = floodcount (x,y+1,arraycopy,value,count)
  File "C:\Users\Geek\Desktop\Light stuff\floodcount.py", line 22, in floodcount
    count = floodcount (x,y+1,arraycopy,value,count)
  File "C:\Users\Geek\Desktop\Light stuff\floodcount.py", line 22, in floodcount
    count = floodcount (x,y+1,arraycopy,value,count)
  File "C:\Users\Geek\Desktop\Light stuff\floodcount.py", line 22, in floodcount
    count = floodcount (x,y+1,arraycopy,value,count)

It does so until “RuntimeError: maximum recursion depth exceeded in cmp”

Any suggestions as to what I am doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:35:27+00:00Added an answer on May 27, 2026 at 12:35 pm

    you seem to be causing a stack overflow. Instead of this recursive solution it may be better to use an array of points to check and push/pop them from that array as you encounter/process them.

    for example:

    create an array called toProcess
    create an array or similar to mark which points have been encountered
    add your start point to toProcess
    while (there are points in toProcess) {
      pop the top/bottom point of toProcess into a temp variable
      process the point
      mark the point as encountered
      if any of the points neighbours are not encountered add them to toProcess
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've asked a question here couple days ago, about how to avoid a function
I asked a question a couple days ago about creating INSERTs by running a
I asked this a couple of days ago on Server Fault but am getting
A couple of days ago I asked a question about how to replace and
I asked this question <input type="hidden" functionality issue a couple of days ago and
I am a beginner and just started learning Python couple days ago (yay!) so
I asked a similar question a couple of days ago, but I'm looking for
I just started learning Python a couple of days ago as my first language
I asked a question a couple of days ago regarding installing numpy on the
This is similar to a question I asked a couple of days ago. However,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.