Spec-Zone.ru › PyTorch 2.14

torch.full_like

torch.full_like(input, fill_value, \*, dtype=None, layout=torch.strided, device=None, requires_grad=False, memory_format=torch.preserve_format) → Tensor

Возвращает тензор того же размера, что и input, заполненный значением fill_value. torch.full_like(input, fill_value) эквивалентен torch.full(input.size(), fill_value, dtype=input.dtype, layout=input.layout, device=input.device).

Параметры:
  • input (Tensor) – размер input определяет размер выходного тензора.
  • fill_value – число, которым заполняется выходной тензор.
Именованные аргументы:
  • dtype (torch.dtype, optional) – требуемый тип данных возвращаемого тензора. По умолчанию: если None, используется тип данных input.
  • layout (torch.layout, optional) – требуемый формат возвращаемого тензора. По умолчанию: если None, используется формат input.
  • device (torch.device, optional) – требуемое устройство возвращаемого тензора. По умолчанию: если None, используется устройство input.
  • requires_grad (bool, optional) – следует ли autograd записывать операции с возвращаемым тензором. По умолчанию: False.
  • memory_format (torch.memory_format, optional) – требуемый формат памяти возвращаемого тензора. По умолчанию: torch.preserve_format.

Пример:

>>> x = torch.ones(2, 3)
>>> torch.full_like(x, 3.141592)
tensor([[ 3.1416,  3.1416,  3.1416],
        [ 3.1416,  3.1416,  3.1416]])
>>> torch.full_like(x, 7)
tensor([[7., 7., 7.],
        [7., 7., 7.]])
>>> torch.full_like(x, 0.5, dtype=torch.int32)
tensor([[0, 0, 0],
        [0, 0, 0]], dtype=torch.int32)
>>> y = torch.randn(3, 4, dtype=torch.float64)
>>> torch.full_like(y, -1.0)
tensor([[-1., -1., -1., -1.],
        [-1., -1., -1., -1.],
        [-1., -1., -1., -1.]], dtype=torch.float64)

© 2026, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://docs.pytorch.org/docs/2.14/generated/torch.full_like.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API