我有np.array
存储在变量x
中,如下所示:
array([[ 956],
[ 929],
[1083],
[1074],
[ 922]]
我想从前一个数字中减去每个数字,我想要一个新的变量y
,如下所示:
array([[ -27],
[ 154],
[ -9],
[-152]]
答案 0 :(得分:2)
import numpy as np
x = np.array([[ 956],
[ 929],
[1083],
[1074],
[ 922]]
out = np.diff(out, axis=0)
Out: array([[ -27],
[ 154],
[ -9],
[-152]]