Can this for
loop be written in a simpler way?
import itertools
import numpy as np
def f(a, b, c): # placeholder for a complex function
print(a+b+c)
a = np.arange(12).reshape(3, 4)
for y, x in itertools.product(range(a.shape[0]-1), range(a.shape[1]-1)):
f(a[y, x], a[y, x+1], a[y+1, x])
The other options I tried, look more convoluted, e.g.:
it = np.nditer(a[:-1, :-1], flags=['multi_index'])
for e in it:
y, x = it.multi_index
f(a[y, x], a[y, x+1], a[y+1, x])