mindspore.dataset.transforms.Fill

查看源文件
class mindspore.dataset.transforms.Fill(fill_value)[源代码]

将Tensor的所有元素都赋值为指定的值。输出Tensor将与输入Tensor具有相同的shape和数据类型。

参数:
  • fill_value (Union[str, bytes, int, float, bool]) - 用于填充Tensor的值。

异常:
  • TypeError - 参数 fill_value 类型不为str、float、bool、int或bytes。

支持平台:

CPU

样例:

>>> import mindspore.dataset as ds
>>> import mindspore.dataset.transforms as transforms
>>> import numpy as np
>>>
>>> # 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)
>>> # [[3], [3], [3], [3], [3]]