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]])
本文深入讲解了numpy.ones函数的使用方法,包括其三个参数:shape、dtype和order的具体含义及用法。通过实例展示了如何创建不同形状和数据类型的数组。
4228

被折叠的 条评论
为什么被折叠?



