Python – PyTorch ceil() method

PyTorch torch.ceil() method returns a new tensor having the ceil value of the elements of input, Which is the smallest integer larger than or equal to each element.

Syntax: torch.ceil(inp, out=None)

Arguments

  • inp: 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:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Importing the PyTorch library 
import torch 
    
# A constant tensor of size n
a = torch.FloatTensor([1.3, -5.6, 7.9, 10.1])
print(a)
  
# Applying the ceil function and 
# storing the result in 'out'
out = torch.ceil(a)
print(out)

chevron_right


Output:

  1.3000
 -5.6000
  7.9000
 10.1000
[torch.FloatTensor of size 4]
  2
 -5
  8
 11
[torch.FloatTensor of size 4]

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Importing the PyTorch library 
import torch 
    
# A constant tensor of size n
a = torch.FloatTensor([1.00001, -5.699, 7.100001, 10.0001])
print(a)
  
# Applying the ceil function and 
# storing the result in 'out'
out = torch.ceil(a)
print(out) 

chevron_right


Output:

 1.0000
 -5.6990
  7.1000
 10.0001
[torch.FloatTensor of size 4]
  2
 -5
  8
 11
[torch.FloatTensor of size 4]
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


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