「Numpy」タプルリストからndarrayに変換する

書式
タプルリスト名 = [(要素1,xxx,xx),(要素2,xx),xxx]
asarray関数を利用してタプルリストから配列に変換します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import numpy as np
lst = [(44,22,33),(7,8)]
res = np.asarray(lst)
print (res)
import numpy as np lst = [(44,22,33),(7,8)] res = np.asarray(lst) print (res)
import numpy as np 
 
lst =  [(44,22,33),(7,8)] 

res = np.asarray(lst)  

print (res)

実行結果
[(44, 22, 33) (7, 8)]

NumPy

Posted by arkgame