Let's say I have a 2D array with a size of m x n elements.
Now, I want to get the indices of all maximums. So the result should be something like:
[(m1, n1), (m2, n2)]
where m
and n
indicate the x and y coordinates of my maximums.
With only one maximum its quite easy, but with more, I'm getting stuck.
import numpy as np
pixel = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 189, 12, 0, 0, 1, 0, 0, 0, 0],
[0, 6, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 203, 9, 0],
[0, 0, 0, 0, 0, 0, 0, 12, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 5, 245, 0, 0, 0, 7, 4, 0],
[0, 0, 0, 0, 0, 0, 0, 250, 8, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
result = np.where(pixel == pixel.max())
print("cross detection at y:", result[0][0], "x:", result[1][0])
print(pixel)
Does somebody have an idea? It would be great, thanks!