Reverse the order of elements along axis 0 (up/down). For a 2-D array, this flips the entries in each column in the up/down direction. Rows are preserved, but appear in a different order than before. Parameters ---------- m : array_like Input array. Returns
(m)
| 119 | |
| 120 | @array_function_dispatch(_flip_dispatcher) |
| 121 | def flipud(m): |
| 122 | """ |
| 123 | Reverse the order of elements along axis 0 (up/down). |
| 124 | |
| 125 | For a 2-D array, this flips the entries in each column in the up/down |
| 126 | direction. Rows are preserved, but appear in a different order than before. |
| 127 | |
| 128 | Parameters |
| 129 | ---------- |
| 130 | m : array_like |
| 131 | Input array. |
| 132 | |
| 133 | Returns |
| 134 | ------- |
| 135 | out : array_like |
| 136 | A view of `m` with the rows reversed. Since a view is |
| 137 | returned, this operation is :math:`\\mathcal O(1)`. |
| 138 | |
| 139 | See Also |
| 140 | -------- |
| 141 | fliplr : Flip array in the left/right direction. |
| 142 | flip : Flip array in one or more dimensions. |
| 143 | rot90 : Rotate array counterclockwise. |
| 144 | |
| 145 | Notes |
| 146 | ----- |
| 147 | Equivalent to ``m[::-1, ...]`` or ``np.flip(m, axis=0)``. |
| 148 | Requires the array to be at least 1-D. |
| 149 | |
| 150 | Examples |
| 151 | -------- |
| 152 | >>> import numpy as np |
| 153 | >>> A = np.diag([1.0, 2, 3]) |
| 154 | >>> A |
| 155 | array([[1., 0., 0.], |
| 156 | [0., 2., 0.], |
| 157 | [0., 0., 3.]]) |
| 158 | >>> np.flipud(A) |
| 159 | array([[0., 0., 3.], |
| 160 | [0., 2., 0.], |
| 161 | [1., 0., 0.]]) |
| 162 | |
| 163 | >>> rng = np.random.default_rng() |
| 164 | >>> A = rng.normal(size=(2,3,5)) |
| 165 | >>> np.all(np.flipud(A) == A[::-1,...]) |
| 166 | True |
| 167 | |
| 168 | >>> np.flipud([1,2]) |
| 169 | array([2, 1]) |
| 170 | |
| 171 | """ |
| 172 | m = asanyarray(m) |
| 173 | if m.ndim < 1: |
| 174 | raise ValueError("Input must be >= 1-d.") |
| 175 | return m[::-1, ...] |
| 176 | |
| 177 | |
| 178 | @finalize_array_function_like |
searching dependent graphs…