I have a 2D numpy array, and I want to perform the following operation:
For each column in the array which is a series of nondecreasing values, replace this column with a column of the differences (that is, each entry is the difference between the two previous ones).
Every other column remains the same (except that first row is removed to fit to the differences columns dimension).
For example, in the matrix:
[ [1,1,1,2,3,4]
[1,3,4,3,4,5]
[1,7,3,4,2,7] ]
[ [0,2,3,1,1,1]
[0,4,1,1,1,2] ]
[ [0,2,4,1,4,1]
[0,4,3,1,2,2] ]
tempX = np.diff(X, axis = 0).transpose()
return np.where(tempX >= 0, tempX, X[1:].transpose())
You could use booleanindexing

# Get the differentiation along first axis
diffs = np.diff(a,axis=0)
# Mask of invalid ones
mask = (diffs<0).any(0)
# Use the mask to set the invalid ones to the original elements
diffs[:,mask] = a[1:,mask]
Sample run 
In [141]: a
Out[141]:
array([[1, 1, 1, 2, 3, 4],
[1, 3, 4, 3, 4, 5],
[1, 7, 3, 4, 2, 7]])
In [142]: diffs = np.diff(a,axis=0)
...: mask = (diffs<0).any(0)
...: diffs[:,mask] = a[1:,mask]
...:
In [143]: diffs
Out[143]:
array([[0, 2, 4, 1, 4, 1],
[0, 4, 3, 1, 2, 2]])