I don't think TensorFlow has the equivalent of numpy.diff, so you have to implement it, which should not be difficult, since numpy. diff is just slicing and subtracting:
def diff(a, n=1, axis=-1): '''(as implemented in NumPy v1.12.0)''' if n == 0: return a if n < 0: raise ValueError( "order must be non-negative but got " + repr(n)) a = asanyarray(a) nd = len(a.shape) slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd slice1[axis] = slice(1, None) slice2[axis] = slice(None, -1) slice1 = tuple(slice1) slice2 = tuple(slice2) if n > 1: return diff(a[slice1]-a[slice2], n-1, axis=axis) else: return a[slice1]-a[slice2]
source share