I imagine the OP has figured this out by now, but for those of you listening...Numpy has some functional programming.I only had to change the function supplied in the question to return integers.Then applied the numpy.apply_along_axis function on a test array:def decrease(a):
return all(a >= a[i+1] for i in range(len(a)-1)) # function to check if a list has decreasing values
def increase(a):
return all(a <= a[i+1] for i in range(len(a)-1)) # function to check if a list has increasing values
def incDec(b):
a=[value for value in b if value !=0]
r = a.index(max(a))
s=a.index(min(a))
inc=a[:r]
dec=a
dec2=a for i in range(len(a)-1))==1:
return 1 # "increasing"
elif all(a >= a[i+1] for i in range(len(a)-1))==1:
return -1 # "decreasing"
elif increase(inc)==1 and decrease(dec)==1:
return 2 # "increasing decreasing"
elif decrease(inc2)==1 and increase(dec2) ==1:
return -2 # "decreasing increasing"
else:
return 0 # mixed
# make test array 2 X 2 X 8 bands
# assuming x and y pixels, with 8 bands
b = [1,2,3,4,5,4,3,2]
c = [1,2,3,4,5,6,7,8]
d = [8,7,6,5,4,3,2,1]
e = [8,7,6,5,6,7,8,9]
nb = np.array(b)
nc = np.array(c)
nd = np.array(d)
ne = np.array(e)
narr = np.indices((2,8))
narr[:] = np.array([[nb,nc],[nd,ne]])
print np.apply_along_axis(incDec, 2, narr)
Ron