「NumPy」arangeで二次元配列のサンプル

書式
import numpy as np
np.arange(数値).reshape(行, 列)

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import numpy as np
arrCft = np.arange(6).reshape(2, 3)
#axis=0 で行を繰り返します
print(arrCft.repeat(2, axis=0))
import numpy as np arrCft = np.arange(6).reshape(2, 3) #axis=0 で行を繰り返します print(arrCft.repeat(2, axis=0))
import numpy as np
arrCft = np.arange(6).reshape(2, 3)
#axis=0 で行を繰り返します
print(arrCft.repeat(2, axis=0))

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[[0 1 2]
[0 1 2]
[3 4 5]
[3 4 5]]
[[0 1 2] [0 1 2] [3 4 5] [3 4 5]]
[[0 1 2]
 [0 1 2]
 [3 4 5]
 [3 4 5]]

 

NumPy

Posted by arkgame