I have a numpy array that I'm iterating through with:
import numpy
import math
array = numpy.array([[1, 1, 2, 8, 2, 2],
[5, 5, 4, 1, 3, 2],
[5, 5, 4, 1, 3, 2],
[5, 5, 4, 1, 3, 2],
[9, 5, 8, 8, 2, 2],
[7, 3, 6, 6, 2, 2]])
Pixels = ['U','D','R','L','UL','DL','UR','DR']
for i in range (1,array.shape[0]-1):
for j in range (1,array.shape[1]-1):
list = []
while len(list) < 2:
iToMakeList = i
jToMakeList = j
if iToMakeList > array.shape[0]-1 or iToMakeList < 1 or jToMakeList> array.shape[0]-1 or jToMakeList < 1:
break
PixelCoord = {
'U' : (iToMakeList-1,jToMakeList),
'D' : (iToMakeList+1,jToMakeList),
'R' : (iToMakeList,jToMakeList+1),
'L' : (iToMakeList,jToMakeList-1),
'UL' : (iToMakeList-1,jToMakeList-1),
'DL' : (iToMakeList+1,jToMakeList-1),
'UR' : (iToMakeList-1,jToMakeList+1),
'DR' : (iToMakeList+1,jToMakeList+1)
}
Value = {
'U' : array[iToMakeList-1][jToMakeList],
'D' : array[iToMakeList+1][jToMakeList],
'R' : array[iToMakeList][jToMakeList+1],
'L' : array[iToMakeList][jToMakeList-1],
'UL' : array[iToMakeList-1][jToMakeList-1],
'DL' : array[iToMakeList+1][jToMakeList-1],
'UR' : array[iToMakeList-1][jToMakeList+1],
'DR' : array[iToMakeList+1][jToMakeList+1]
}
candidates = []
for pixel in Pixels:
candidates.append((Value[pixel],pixel))
Lightest = max(candidates)
list.append(PixelCoord[Lightest[1]])
iToMakeList = PixelCoord[Lightest[1]][0]
jToMakeList = PixelCoord[Lightest[1]][1]
I want to accelerate this process. It's very slow.
Assume that the output of this snippet is my final goal and the ONLY thing I want to do is accelerate this code.