megengine.functional.full

full(shape, value, *, dtype=None, device=None)[源代码]

Returns a new tensor having a specified shape and filled with given value.

参数
  • shape (int...) – 输出张量的形状。

  • value (Scalar) – 填充值

关键字参数
  • dtype (Tensor.dtype, optional) – output tensor data type. If dtype is None, the output tensor data type must be inferred from value. If the value is an int, the output tensor data type must be the default integer data type. If the value is a float, the output tensor data type must be the default floating-point data type. If the value is a bool, the output tensor must have boolean data type.

  • device (Tensor.device, optional) – device on which to place the created tensor.

返回类型

Tensor

返回

一个全value的tensor

实际案例

>>> F.full((2, 3), 6)
Tensor([[6 6 6]
 [6 6 6]], dtype=int32, device=xpux:0)