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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


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]])

 

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up

Recommended Posts:

    Article Tags :

    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.