NumPy⑥ (ラジアンと角度の相互変換)

ラジアンと角度の相互変換

NumPyで実装されている三角関数系の関数は、基本的にラジアンを引数に設定します。

角度に π / 180 をかけるとラジアンに変換でき、ラジアンに 180 / π をかけると角度に変換できます。

NumPyにはこれらの変換処理を行う関数が用意されています。

  • radians()、deg2rad()
    角度をラジアンに変換する。
  • rad2deg()
    ラジアンを角度に変換する。

[Google Colaboratory]

1
2
3
4
import numpy as np
x = np.array([90, 180, 270], dtype = np.float)

np.radians(x) # 角度をラジアンに変換

[実行結果]

[Google Colaboratory]

1
np.deg2rad(x)              # 角度をラジアンに変換

[実行結果]

[Google Colaboratory]

1
np.rad2deg(np.deg2rad(x))  # ラジアンを角度に変換

[実行結果]