mindspore.Tensor.fill

Tensor.fill(value)[source]

Fill the tensor with a scalar value.

Note

Unlike Numpy, tensor.fill() will always return a new tensor, instead of filling the original tensor.

Parameters

value (Union[None, int, float, bool]) – All elements of a will be assigned this value.

Returns

Tensor, with the original dtype and shape.

Raises

TypeError – If input arguments have types not specified above.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import numpy as np
>>> from mindspore import Tensor
>>> a = Tensor(np.arange(4).reshape((2,2)).astype('float32'))
>>> print(a.fill(1.0))
[[1. 1.]
[1. 1.]]