I have to process a lot of arrays, they contain 512x256 pixel-like data, however most entries are 0, so I want to only save the non-zero values, i.e.:
import numpy as np
import time
xlist=[]
ylist=[]
zlist=[]
millis = time.time()*1000
ar = np.zeros((512,256),dtype=np.uint16)
for x in range(0,512):
for y in range(0,256):
if (0<ar[x][y]<1000):
xlist.append(x)
ylist.append(y)
zlist.append(ar[x][y])
print time.time()*1000-millis
this takes about 750ms on my pc. Is there a way to do this faster? I have to process tens of thousands of these pixel arrays.
rangetoxrangecould get you a tiny performance increase.