Just figured out that 2 nested loops work extremely slow in Python. CPU load stays around 0% but it still works slow. Why? How can I fix that?
Initialization (shouldn't comment it to make it work fast):
a = imresize(image, (maxY, maxX), 'lanczos')
b = imresize(image, (maxY * 2, maxX), 'lanczos')
Slow code:
result = np.empty((maxY, maxX, 3), dtype=np.uint16)
for y in range(maxY):
for x in range(maxX):
result[y, x] = [a[y, x], a[y, x], a[y, x]]
And this one works even more slow:
result = np.empty((maxY, maxX, 3), dtype=np.uint16)
for y in range(maxY):
for x in range(maxX):
result[y, x] = [a[y, x], b[y*2, x], b[y*2+1, x]]
Is there any other more effective code to achieve the same results?
Shape of a is (299, 299), b - (598, 299), result - (299, 299, 3). I call the code about 5000 times (and wait about 10 minutes for that amount of data).
If I comment the provided code everything works just a second.