admin管理员组文章数量:1642430
分类目录:《深入浅出PaddlePaddle函数》总目录
相关文章:
· 深入浅出PaddlePaddle函数——paddle.Tensor
· 深入浅出PaddlePaddle函数——paddle.ones
· 深入浅出PaddlePaddle函数——paddle.zeros
· 深入浅出PaddlePaddle函数——paddle.full
· 深入浅出PaddlePaddle函数——paddle.ones_like
· 深入浅出PaddlePaddle函数——paddle.zeros_like
· 深入浅出PaddlePaddle函数——paddle.full_like
创建一个形状为shape
、数据类型为dtype
且值全为fill_value
的Tensor。
语法
paddle.full(shape, fill_value, dtype=None, name=None)
参数
shape
:[tuple
/list
/Tensor
] 要创建的Tensor的形状,shape
的数据类型为int32
或int64
。fill_value
:[bool
/float
/int
/Tensor
] 用于初始化输出Tensor的常量数据的值。注意:该参数不可超过输出变量数据类型的表示范围。dtype
:[可选,np.dtype
/str
] 要创建的Tensor的数据类型,可以为bool
、float16
、float32
、float64
、int32
或int64
。如果dtype
为None
,那么数据类型为float32
。name
:[可选,str
] 具体用法请参见Name
,一般无需设置,默认值为None
。
返回值
Tensor,每个元素都是fill_value
,形状为 shape
,数据类型为dtype
。
实例
import paddle
data1 = paddle.full(shape=[2,1], fill_value=0, dtype='int64')
#[[0]
# [0]]
# attr shape is a list which contains Tensor.
positive_2 = paddle.full([1], 2, "int32")
data3 = paddle.full(shape=[1, positive_2], dtype='float32', fill_value=1.5)
# [[1.5 1.5]]
# attr shape is a Tensor.
shape = paddle.full([2], 2, "int32")
data4 = paddle.full(shape=shape, dtype='bool', fill_value=True)
# [[True True]
# [True True]]
# attr fill_value is a Tensor.
val = paddle.full([1], 2.0, "float32")
data5 = paddle.full(shape=[2,1], fill_value=val, dtype='float32')
# [[2.0]
# [2.0]]
函数实现
def full(shape, fill_value, dtype=None, name=None):
"""
Return a Tensor with the ``fill_value`` which size is same as ``shape``.
Args:
shape(list|tuple|Tensor): Shape of the Tensor to be created.
The data type is ``int32`` or ``int64`` . If ``shape`` is a list or tuple,
the elements of it should be integers or Tensors with shape [1].
If ``shape`` is an Tensor, it should be an 1-D Tensor.
fill_value(bool|float|int|Tensor): The constant value
used to initialize the Tensor to be created. If ``fill_value`` is an Tensor, it must be an 1-D Tensor.
dtype(np.dtype|str, optional): Data type of the output Tensor
which can be float16, float32, float64, int32, int64, if dytpe is `None`, the data
type of created Tensor is `float32`.
name (str, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None.
Returns:
Tensor: Tensor which is created according to ``shape``, ``fill_value`` and ``dtype``.
Examples:
.. code-block:: python
import paddle
data1 = paddle.full(shape=[2,1], fill_value=0, dtype='int64')
#[[0]
# [0]]
# attr shape is a list which contains Tensor.
positive_2 = paddle.full([1], 2, "int32")
data3 = paddle.full(shape=[1, positive_2], dtype='float32', fill_value=1.5)
# [[1.5 1.5]]
# attr shape is a Tensor.
shape = paddle.full([2], 2, "int32")
data4 = paddle.full(shape=shape, dtype='bool', fill_value=True)
# [[True True]
# [True True]]
# attr fill_value is a Tensor.
val = paddle.full([1], 2.0, "float32")
data5 = paddle.full(shape=[2,1], fill_value=val, dtype='float32')
# [[2.0]
# [2.0]]
"""
if dtype is None:
dtype = 'float32'
return fill_constant(shape=shape, dtype=dtype, value=fill_value, name=name)
本文标签: 深入浅出函数fullpaddlepaddlePaddle
版权声明:本文标题:深入浅出PaddlePaddle函数——paddle.full 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1729340728a1197499.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论