2

Here is my question.
Assuming there is a 2-D array data in the shape of 100 x 100. Using:

indices =  np.argpartition(data.flatten(),-200)[-200:][::-1]
loc = np.vstack(np.unravel_index(indices,data.shape)).T
loc = pd.DataFrame(loc)   

I can get the location index of 200 largest value.

But how to search the peak of the 2-d array. For express more claerly, I plotted an 3-d figure to show the "peak". IMHO that, peak is the location which value greater than its nearby grid but may be not matter for the whole area.

enter image description here

In the figure above, some peak are plotted in red due to its highest value, some peak are plotted in green due to it non-large value.

Is there any method to search for these peak on the whole area.

For now, I have an idea to loop all grid and its nearby grids. If the value of one grid was higher than any of its surroundings, this grid point will be thought as an peak.

Han Zhengzu
  • 3,694
  • 7
  • 44
  • 94
  • 2
    Is this what you're after http://stackoverflow.com/questions/3684484/peak-detection-in-a-2d-array? – Ilja Everilä Apr 15 '16 at 16:19
  • Thanks for your reply. I have checked the best answer.`from scipy.ndimage.filters import maximum_filter` is a solution aiming to picture. Does it fit with 2-d numpy array too? – Han Zhengzu Apr 15 '16 at 16:29
  • 1
    Well, pictures are 2d arrays (3d too, RGB etc.). Rest is interpretation. Your problem to me seems exactly a local maxima problem. – Ilja Everilä Apr 15 '16 at 16:45
  • 2
    In general this is an optimization problem. You are looking for all maxima, both local and global. Standard optimization algorithms will find local maxima based on derivatives. Global maxima can be found with evaluating the whole function with brute force (which you have already done) or by sampling the function (Monte Carlo) in many random places , by genetic algorithms, by simulated annealing. This can be hard if you have many dimensions with high resolution. In your case you already know all values. You just look for `np.argmax`. – roadrunner66 Apr 16 '16 at 04:55
  • Thanks for your reply. I have fixed this question using `filters.maximum_filter`. What you have introduced was interesting. By the way, I'm learning GA now. And I can't have an solution to achieve this target using GA method. IMHO that I use GA for an individuals in a certain dimensions. For this case, I can't determine the number of local maximum before I search it. – Han Zhengzu Apr 16 '16 at 05:14

0 Answers0