Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.full function

PyTorch torch.full function


PyTorch torch reference manual PyTorch torch reference manual

torch.full A function in PyTorch for creating a tensor filled with a specified value.

Function definition

torch.full(size, fill_value, dtype=None, device=None, requires_grad=False)


Usage examples

Example

import

torch

Create a 3x4 tensor filled with the value 7

x

=

torch.

full

(

(

3

,

4

)

,

7

)

print

(

x

)

The output is:

tensor([[7., 7., 7., 7.],

        [7., 7., 7., 7.],

        [7., 7., 7., 7.]])


PyTorch torch reference manual PyTorch torch reference manual