numpy API: numpy.flipud
Flip array in the up/down direction. 对数组进行上下翻转。
例子:
A = np.random.randn(2,3,5)
# 相当于从最后一个元素开始翻转
A[::-1]
array([[[ 0.7264141 , -0.68764277, -2.03427692, -0.2503444 ,
0.07066799],
[ 1.24399152, -1.62818959, -0.59335682, 0.33902456,
0.19938865],
[ 0.67396361, 0.02082263, 0.35908906, 0.16785502,
0.83287606]],
[[-1.1990758 , 1.11397922, -0.09542215, -0.79583185,
-0.424901 ],
[-0.40933983, -1.23828286, -0.46399485, -0.20731838,
-0.70738003],
[-0.47824641, -1.24502222, 0.63792145, 0.23233168,
-0.78067298]]])
# A矩阵反转的操作等价
np.all(np.flipud(A) == A[::-1])
True