numpy.full
numpy.full(shape, fill_value, dtype=None, order='C')[source]
返回一个根据指定shape和type,并用fill_value填充的新数组。
参数: | shape:整数或整数序列 新数组的形态,单个值代表一维,参数传元组,元组中元素个数就代表是几维,例如, (2, 3) or 2. fill_value: 标量(无向量) 填充数组的值 dtype:数据类型,可选 默认值为None 查看要填充数组的值数据类型:np.array(fill_value).dtype。 order:{‘C’, ‘F’}, 可选 是否在内存中以行为主(C风格)或列为主(Fortran风格)连续(行或列)顺序存储多维数据。 |
返回值: | 返回值类型 : ndarray(ndarray是N维数组对象) 根据指定的参数生成的数组 |
例如,
>>> numpy.array(3).dtype
dtype('int64')
>>> numpy.array(3.34).dtype
dtype('float64')
>>>
>>> numpy.full((2, 2), np.inf)
array([[ inf, inf],
[ inf, inf]])
>>> numpy.full((2, 2), 10)
array([[10, 10],
[10, 10]])
>>> print(numpy.full((2,2),2,"int64"))
[[2 2]
[2 2]]
>>> print(numpy.full((2,2),2,"int32"))
[[2 2]
[2 2]]
>>> print(numpy.full((2,2),2,, dtype=numpy.long))
[[2 2]
[2 2]]
>>> print(numpy.full((2,4,3),2,"float"))
[[[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]]
[[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]]]
>>> print(numpy.full((4,4,3),2,"double"))
[[[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]]
[[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]]
[[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]]
[[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]
[2. 2. 2.]]]
>>>