mindspore.ops.fill

View Source On Gitee
mindspore.ops.fill(type, shape, value)[source]

Create a Tensor of the specified shape and fill it with the specified value.

Parameters
  • type (mindspore.dtype) – The specified type of output tensor. The data type only supports bool_ and number .

  • shape (Union(Tensor, tuple[int])) – The specified shape of output tensor.

  • value (Union(Tensor, number.Number, bool)) – Value to fill the returned tensor.

Returns

Tensor.

Raises

TypeError – If shape is not a tuple or a tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> from mindspore import ops
>>> 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.]]