「NumPy」ones()で全ての要素が1の行列を作る

書式
import numpy as np
np.ones(数値)
ones()関数で全ての要素が1の行列を作成します。

使用例

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

実行結果

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

 

NumPy

Posted by arkgame