「NumPy」linspace関数でstart と step に数値のシーケンスを渡す

書式
np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)
パラメーター
start: 開始数値を指定します。
stop: 終了数値を指定します。
start と step には要素が数値の配列やリスト・タプルなどのシーケンスを渡すことができます。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import numpy as np
# start と step には配列やリスト等を渡す
x = np.array([0, 50])
y = [10, 80]
res = np.linspace(x, y, num=5)
print(res)
import numpy as np # start と step には配列やリスト等を渡す x = np.array([0, 50]) y = [10, 80] res = np.linspace(x, y, num=5) print(res)
import numpy as np

#  start と step には配列やリスト等を渡す
x = np.array([0, 50])
y = [10, 80]
res = np.linspace(x, y, num=5)

print(res)

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[[ 0. 50. ]
[ 2.5 57.5]
[ 5. 65. ]
[ 7.5 72.5]
[10. 80. ]]
[[ 0. 50. ] [ 2.5 57.5] [ 5. 65. ] [ 7.5 72.5] [10. 80. ]]
[[ 0.  50. ]
 [ 2.5 57.5]
 [ 5.  65. ]
 [ 7.5 72.5]
 [10.  80. ]]

 

NumPy

Posted by arkgame