「NumPy」linspace関数にretstepを指定し公差を取得する

書式
np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)
パラメーター
start: 開始数値を指定します。
stop: 終了数値を指定します。
num: 生成する配列の要素の数(長さ)を指定します。
endpoint: デフォルトのTrueでは、stopで指定した数値が生成される配列に含まれます。
retstep=True にすると、配列とともに公差を戻してくれます。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import numpy as np
# retstep=True で公差を取得
res = np.linspace(3.0, 4.0, num=5, retstep=True)
print(res)
import numpy as np # retstep=True で公差を取得 res = np.linspace(3.0, 4.0, num=5, retstep=True) print(res)
import numpy as np

# retstep=True で公差を取得
res = np.linspace(3.0, 4.0, num=5, retstep=True)

print(res)

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
(array([3. , 3.25, 3.5 , 3.75, 4. ]), 0.25)
(array([3. , 3.25, 3.5 , 3.75, 4. ]), 0.25)
(array([3.  , 3.25, 3.5 , 3.75, 4.  ]), 0.25)

 

NumPy

Posted by arkgame