numpy.flipud#
- numpy.flipud(m)[源代码]#
沿轴 0(向上/向下)反转元素的顺序。
对于二维数组,这会在向上/向下方向上翻转每列中的条目。行被保留,但出现的顺序与之前不同。
- 参数:
- marray_like
输入数组。
- 返回:
- outarray_like
m 的一个视图,其中行已反转。由于返回的是视图,此操作的复杂度为 \(\mathcal O(1)\)。
注释
等价于
m[::-1, ...]
或np.flip(m, axis=0)
。要求数组至少为一维。示例
>>> import numpy as np >>> A = np.diag([1.0, 2, 3]) >>> A array([[1., 0., 0.], [0., 2., 0.], [0., 0., 3.]]) >>> np.flipud(A) array([[0., 0., 3.], [0., 2., 0.], [1., 0., 0.]])
>>> rng = np.random.default_rng() >>> A = rng.normal(size=(2,3,5)) >>> np.all(np.flipud(A) == A[::-1,...]) True
>>> np.flipud([1,2]) array([2, 1])