Equivalent function like `numpy.diff` in pytorch?

I think indexing should just work:

x = torch.tensor([1, 2, 4, 7, 0])
x_diff = x[1:] - x[:-1]
print(x_diff)
> tensor([ 1,  2,  3, -7])