「NumPy」ゼロ行列の配列を作るサンプル

書式
import numpy as np
np.zeros(要素数)
全ての要素が 0 のゼロ行列は、zeros() 関数で作ります。
第一引数で要素の個数を、オプション引数で dtype を渡します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import numpy as np
arr = np.zeros(12).reshape(3, 4)
print(arr)
import numpy as np arr = np.zeros(12).reshape(3, 4) print(arr)
import numpy as np
arr = np.zeros(12).reshape(3, 4)
print(arr)

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]
[[0. 0. 0. 0.] [0. 0. 0. 0.] [0. 0. 0. 0.]]
[[0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]]

 

NumPy

Posted by arkgame