Python Forum
Help improve code efficiency
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help improve code efficiency
#4
When you do Cnew[i][j] = 1, just append a tuple of the coordinates to you contaminated list: contaminated.append((i, j)). Then you loop through that list with for cx, xy in contaminated:.

Now, you'll have to do the check for the next set of cells in reverse. I would suggest a dictionary of tuples, reset each generation to empty. Ideally this would be a defaultdict, but you could just use get with a 0 default. So go through the neighbors of each contaminated space, and add one to the dictionary for the neighbor's coordinates. After all the contaminated squares are checked, loop through the dictionary and use the totals to check for new contaminations. Add those to your contaminated list.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Help improve code efficiency - by benbrown03 - Feb-12-2019, 02:06 PM
RE: Help improve code efficiency - by ichabod801 - Feb-12-2019, 03:38 PM
RE: Help improve code efficiency - by benbrown03 - Feb-12-2019, 05:34 PM
RE: Help improve code efficiency - by ichabod801 - Feb-12-2019, 08:22 PM
RE: Help improve code efficiency - by benbrown03 - Feb-19-2019, 10:56 AM
RE: Help improve code efficiency - by ichabod801 - Feb-19-2019, 08:04 PM
RE: Help improve code efficiency - by benbrown03 - Feb-19-2019, 09:25 PM
RE: Help improve code efficiency - by ichabod801 - Feb-19-2019, 10:08 PM
RE: Help improve code efficiency - by benbrown03 - Feb-20-2019, 08:04 AM
RE: Help improve code efficiency - by ichabod801 - Feb-20-2019, 03:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Numpy Structure and Efficiency garynewport 2 740 Oct-19-2022, 10:11 PM
Last Post: paul18fr
  (OpenCV) Help to improve code for object detection and finding center of it saoko 0 1,231 May-14-2022, 05:34 PM
Last Post: saoko
  Efficiency with regard to nested conditionals or and statements Mark17 13 3,304 May-06-2022, 05:16 PM
Last Post: Mark17
  How to use vectorization instead of for loop to improve efficiency in python? PJLEMZ 4 2,474 Feb-06-2021, 09:45 AM
Last Post: paul18fr
  Any suggestions to improve BuySell stock problem efficiency? mrapple2020 0 1,397 May-13-2020, 06:19 PM
Last Post: mrapple2020
  how can I improve the code to get it faster? aquerci 2 1,760 Feb-15-2020, 02:52 PM
Last Post: aquerci
  How can I improve this piece of code? aquerci 3 2,243 Nov-17-2019, 10:57 AM
Last Post: Gribouillis
  How to improve the quality of my code? grobattac37 3 2,537 Jan-25-2019, 06:17 PM
Last Post: ichabod801
  Web Scraping efficiency improvement HiImNew 0 2,419 Jun-01-2018, 08:52 PM
Last Post: HiImNew
  Improving Efficiency of SVM by various available kernels Sachtech 0 2,124 Apr-09-2018, 07:29 AM
Last Post: Sachtech

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020