ones(shape, dtype=None, order='C')
ones三个参数parameter的含义:
- shape:整数型 “2” 或者序列 (2,3)
- deype:数据类型,可以选择为整型,default默认为64byte的浮点型
- 命令:可以选择为“C”型或“F”型来存储数据。
函数的输出:ndarray
函数有的输出由上面三个参数给定的形式来输出的数组。
import numpy as np
np.ones(5)
# 输出为array([ 1., 1., 1., 1., 1.])
np.ones((5,), dtype=np.int)
# 输出array([1, 1, 1, 1, 1])
np.ones((2,1))
# 输出为array([[ 1.];[ 1.]])
np.ones((2,2), dtype=np.int)
# 输出为array([[1,1];[1,1]])