Open In App

Python - PyTorch ceil() method

Last Updated : 26 May, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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: Python3
# 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)
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: Python3
# 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) 
Output:
 1.0000
 -5.6990
  7.1000
 10.0001
[torch.FloatTensor of size 4]
  2
 -5
  8
 11
[torch.FloatTensor of size 4]

Next Article
Article Tags :
Practice Tags :

Similar Reads