I have a 2D aray of size(640X480) like this :
[[1.2 , 9.5 , 4.8 , 1.7],
[5.5 , 8.1 , 7.6 , 7.1],
[1.4 , 6.9 , 7.8 , 2.2]] (this is a sample of a 4X3 array)
I have to find the top 100(or N) highest values in the array, in the FASTEST way possible; so I need the most optimised code which takes least processing time.
Since it is a giant array, it is fine if i only checked every 2nd element or every 3rd or 4th element.
The output of the algorithm should be a list of tuple, each tuple being the 2D index of the high-value element.
For example the index for 9.5 would be (0,1)
I have found a solution but it is too slow:
indexes=[]
for i in range(100):
highest=-1
highindex=0.1
for indi,i in enumerate(array):
for indj,j in enumerate(i):
if j>highest and not((indi,indj) in indexes):
highest= j
highindex=(indi,indj)
indexes.append(highindex)