numpy.diff(a, n=1,axis=-1)
参数:
a:输入矩阵
n:可选,代表要执行几次差值
axis:默认是最后一个
import numpy as np
arr = np.arange(12).reshape(3,4)
arr
#array([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
print(np.diff(arr))
# [[1 1 1]
[1 1 1]
[1 1 1]]