mindspore.ops.fill

mindspore.ops.fill(type, shape, value)[源代码]

创建一个指定shape的Tensor,并用指定值填充。

参数:
  • type (mindspore.dtype) - 指定输出Tensor的数据类型。数据类型只支持 bool_number

  • shape (tuple[int]) - 指定输出Tensor的shape。

  • value (Union(number.Number, bool)) - 用来填充输出Tensor的值。

返回:

Tensor。

异常:
  • TypeError - shape 不是元组。

支持平台:

Ascend GPU CPU

样例:

>>> output = ops.fill(mindspore.float32, (2, 2), 1)
>>> print(output)
[[1. 1.]
 [1. 1.]]
>>> output = ops.fill(mindspore.float32, (3, 3), 0)
>>> print(output)
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]