Friday, October 24, 2025
HomeLanguagesPython – PyTorch floor() method

Python – PyTorch floor() method

PyTorch torch.floor() method returns a new tensor which is floor of the elements of input, the largest integer less than or equal to each element.
floor method

Syntax: torch.floor(input, out=None)

Arguments

  • input: This is input tensor.
  • out: The output tensor.

Return: It returns a Tensor.

Let’s see this concept with the help of few examples:
Example 1:




# Importing the PyTorch library 
import torch 
    
# A constant tensor of size n
a = torch.FloatTensor([1.5, 4.2, 6.7, 3.9])
print(a)
  
# Applying the floor function and 
# storing the result in 'out'
out = torch.floor(a)
print(out)


Output:

 1.5000
 4.2000
 6.7000
 3.9000
[torch.FloatTensor of size 4]

 1
 4
 6
 3
[torch.FloatTensor of size 4]

Example 2:




# Importing the PyTorch library 
import torch 
    
# A constant tensor of size n
a = torch.FloatTensor([1.59, 4.5999, 6.78, 3.99999])
print(a)
  
# Applying the floor function and 
# storing the result in 'out'
out = torch.floor(a)
print(out)


Output:

1.5900
 4.5999
 6.7800
 4.0000
[torch.FloatTensor of size 4]

 1
 4
 6
 3
[torch.FloatTensor of size 4]
Last Updated :
26 May, 2020
Like Article
Save Article

<!–

–>

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

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS