MCPcopy Create free account
hub / github.com/numpy/numpy / rot90

Function rot90

numpy/lib/function_base.py:159–247  ·  view source on GitHub ↗

Rotate an array by 90 degrees in the plane specified by axes. Rotation direction is from the first towards the second axis. This means for a 2D array with the default `k` and `axes`, the rotation will be counterclockwise. Parameters ---------- m : array_like Ar

(m, k=1, axes=(0, 1))

Source from the content-addressed store, hash-verified

157
158@array_function_dispatch(_rot90_dispatcher)
159def rot90(m, k=1, axes=(0, 1)):
160 """
161 Rotate an array by 90 degrees in the plane specified by axes.
162
163 Rotation direction is from the first towards the second axis.
164 This means for a 2D array with the default `k` and `axes`, the
165 rotation will be counterclockwise.
166
167 Parameters
168 ----------
169 m : array_like
170 Array of two or more dimensions.
171 k : integer
172 Number of times the array is rotated by 90 degrees.
173 axes : (2,) array_like
174 The array is rotated in the plane defined by the axes.
175 Axes must be different.
176
177 .. versionadded:: 1.12.0
178
179 Returns
180 -------
181 y : ndarray
182 A rotated view of `m`.
183
184 See Also
185 --------
186 flip : Reverse the order of elements in an array along the given axis.
187 fliplr : Flip an array horizontally.
188 flipud : Flip an array vertically.
189
190 Notes
191 -----
192 ``rot90(m, k=1, axes=(1,0))`` is the reverse of
193 ``rot90(m, k=1, axes=(0,1))``
194
195 ``rot90(m, k=1, axes=(1,0))`` is equivalent to
196 ``rot90(m, k=-1, axes=(0,1))``
197
198 Examples
199 --------
200 >>> m = np.array([[1,2],[3,4]], int)
201 >>> m
202 array([[1, 2],
203 [3, 4]])
204 >>> np.rot90(m)
205 array([[2, 4],
206 [1, 3]])
207 >>> np.rot90(m, 2)
208 array([[4, 3],
209 [2, 1]])
210 >>> m = np.arange(8).reshape((2,2,2))
211 >>> np.rot90(m, 1, (1,2))
212 array([[[1, 3],
213 [0, 2]],
214 [[5, 7],
215 [4, 6]]])
216

Callers 3

test_basicMethod · 0.90
test_axesMethod · 0.90
test_rotation_axesMethod · 0.90

Calls 4

transposeFunction · 0.90
asanyarrayFunction · 0.85
arangeFunction · 0.85
flipFunction · 0.70

Tested by 3

test_basicMethod · 0.72
test_axesMethod · 0.72
test_rotation_axesMethod · 0.72