Friday, August 29, 2025
HomeLanguagesPython Pytorch full() method

Python Pytorch full() method

PyTorch is an open-source machine learning library developed by Facebook. It is used for deep neural network and natural language processing purposes.

The function torch.full() returns a tensor of size size filled with fill_value.

Syntax: torch.ones(size, fill_value, out=None)

Parameters:
size: a sequence of integers defining the shape of the output tensor
fill_value: the number to fill the output tensor with.
out (Tensor, optional): the output tensor

Return type: A tensor

Code #1:




# Importing the PyTorch library
import torch
  
  
# Applying the full function and
# storing the resulting tensor in 'a'
a = torch.full([3, 4], 3)
print("a = ", a)
  
b = torch.full([2, 5], 3.5)
print("b = ", b)


Output:

a =  tensor([[3., 3., 3., 3.],
        [3., 3., 3., 3.],
        [3., 3., 3., 3.]])
b =  tensor([[3.5000, 3.5000, 3.5000, 3.5000, 3.5000],
        [3.5000, 3.5000, 3.5000, 3.5000, 3.5000]])

 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32249 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11790 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11838 POSTS0 COMMENTS
Shaida Kate Naidoo
6731 POSTS0 COMMENTS
Ted Musemwa
7012 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6701 POSTS0 COMMENTS