for i in range(w, nx - w):
    for j in range(w, ny - w):
        sampleframe = im[j - w:j + w, i - w:i + w]
variance = np.var(sampleframe)
varianceMatrix[j][i] = variance
return varianceMatrix
np.set_printoptions(linewidth=1000, edgeitems=5)
start = time.time()
print(sliding_img_var(img, 1))
time_sliding = time.time() - start
start = time.time()
print(looping_img_var(img, 1))
time_looping = time.time() - start
print('duration: sliding: {0} s, looping: {1} s'.format(time_sliding,
    time_looping))
Calculating variance of an image python efficiently