「Numpy」繰り返された配列を作成するサンプル

書式
配列名 =np.array([要素1, xxx])
配列名.repeat(回数)
repeatを使用すると、繰り返された配列を作成します。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import numpy as np
resArr = np.array(["s", "t", "u"])
print(resArr.repeat(3))
import numpy as np resArr = np.array(["s", "t", "u"]) print(resArr.repeat(3))
import numpy as np

resArr = np.array(["s", "t", "u"])

print(resArr.repeat(3))

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
['s' 's' 's' 't' 't' 't' 'u' 'u' 'u']
['s' 's' 's' 't' 't' 't' 'u' 'u' 'u']
['s' 's' 's' 't' 't' 't' 'u' 'u' 'u']

 

NumPy

Posted by arkgame