「Python」numpy.rot90()の基本使い方

環境
Python3.9.2
PyCharm 2021.3.3

構文
np.rot90(配列名)
デフォルトでは反時計回りに90度回転します。
numpy.rot90()の第一引数に回転させたいndarrayを指定します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import numpy as np
cft = np.arange(6).reshape(2, 3)
print(cft)
print("90度回転する結果")
res = np.rot90(cft)
print(res)
import numpy as np cft = np.arange(6).reshape(2, 3) print(cft) print("90度回転する結果") res = np.rot90(cft) print(res)
import numpy as np

cft = np.arange(6).reshape(2, 3)
print(cft)

print("90度回転する結果")
res = np.rot90(cft)
print(res)

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[[0 1 2]
[3 4 5]]
90度回転する結果
[[2 5]
[1 4]
[0 3]]
[[0 1 2] [3 4 5]] 90度回転する結果 [[2 5] [1 4] [0 3]]
[[0 1 2]
 [3 4 5]]
90度回転する結果
[[2 5]
 [1 4]
 [0 3]]

 

NumPy

Posted by arkgame