mindspore.dataset.transforms.Fill

View Source On Gitee
class mindspore.dataset.transforms.Fill(fill_value)[source]

Tensor operation to fill all elements in the tensor with the specified value. The output tensor will have the same shape and type as the input tensor.

Parameters

fill_value (Union[str, bytes, int, float, bool]) – scalar value to fill the tensor with.

Raises

TypeError – If fill_value is not of type str, float, bool, int or bytes.

Supported Platforms:

CPU

Examples

>>> import numpy as np
>>> import mindspore.dataset as ds
>>> import mindspore.dataset.transforms as transforms
>>>
>>> # Use the transform in dataset pipeline mode
>>> # generate a 1D integer numpy array from 0 to 4
>>> def generator_1d():
...     for i in range(5):
...         yield (np.array([i]),)
>>> generator_dataset = ds.GeneratorDataset(generator_1d, column_names="col1")
>>> # [[0], [1], [2], [3], [4]]
>>> fill_op = transforms.Fill(3)
>>> generator_dataset = generator_dataset.map(operations=fill_op)
>>> for item in generator_dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
...     print(item["col1"].shape, item["col1"].dtype)
...     break
(1,) int64
>>>
>>> # Use the transform in eager mode
>>> data = np.array([1, 2, 3])
>>> output = transforms.Fill(100)(data)
>>> print(output.shape, output.dtype)
(3,) int64