Python Forum
Neighbours in an array
Thread Rating:
  • 3 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Neighbours in an array
#9
My previous reply was basically the answer.  
for y, x in inp2:
    # set maximum to the current value 
    for dy, dx in ADJACENTS:
        if 0 <= y+dy < P and 0 <= x+dx < Q:
            # set maximum to adjacent value if higher than current maximum
    # set the location in the new array to the maximum
Just replace the lines.  You still index into inp1 with the coordinates (x, y, x+dx, y+dy).

Set the initial maximum to inp1[y,x]
Then on line four set maximum to the adjacent you are checking inp1[y+dy, x+dx] if that is higher than current maximum.
On line five set inp_new[y,x] to the maximum.
Reply


Messages In This Thread
Neighbours in an array - by MattaFX - Jan-20-2017, 04:26 PM
RE: Neighbours in an array - by Mekire - Jan-20-2017, 11:06 PM
RE: Neighbours in an array - by MattaFX - Jan-21-2017, 12:15 AM
RE: Neighbours in an array - by Mekire - Jan-21-2017, 12:59 AM
RE: Neighbours in an array - by MattaFX - Jan-21-2017, 12:59 PM
RE: Neighbours in an array - by MattaFX - Jan-22-2017, 12:11 AM
RE: Neighbours in an array - by Mekire - Jan-22-2017, 03:19 AM
RE: Neighbours in an array - by MattaFX - Jan-24-2017, 08:16 PM
RE: Neighbours in an array - by Mekire - Jan-24-2017, 10:46 PM
RE: Neighbours in an array - by MattaFX - Jan-25-2017, 11:02 PM
RE: Neighbours in an array - by Mekire - Jan-26-2017, 02:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to find the accuracy vs number of neighbours for KNN vokoyo 3 3,201 Apr-10-2019, 03:46 AM
Last Post: scidam

Forum Jump:

User Panel Messages

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