Is there a way to optimize this snippet of code? With my current im value, it is taking me ~28 seconds. Wondering if I could reduce this time.
im = output_image[-min_xy[1]:-min_xy[1] + image_2.shape[0], -min_xy[0]:-min_xy[0] + image_2.shape[1]]
for idx, rk in enumerate(im):
for ix, k in enumerate(rk):
image_2[idx][ix] = avg(im[idx][ix], image_2[idx][ix])
type(image_2) and type(im) is <type 'numpy.ndarray'>
im.shape and image_2.shape is (2386, 3200, 3)
what my avg() does is
def avg(a1, a2):
if [0., 0., 0.] in a1:
return a2
else:
return (a1 + a2) / 2
NOTE: a1 is an array of size 3 ex: array([ 0.68627451, 0.5372549 , 0.4745098])
if [0., 0., 0.] in a1its checking if anyone ina1is zero. Are you sure you want that?if [0., 0., 0.] in a1:, are you trying to check ifALLelements ina1are zeros OR ifANYone element ina1is zero?