VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-get-the-floor-ceiling-and-truncated-values-of-the-elements-of-a-numpy-array/

⇱ How to get the floor, ceiling and truncated values of the elements of a numpy array? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to get the floor, ceiling and truncated values of the elements of a numpy array?

Last Updated : 15 Jul, 2025

In this article, let's discuss how to get the floor, ceiling, and truncated values of the elements of a Numpy array. First, we need to import the NumPy library to use all the functions available in it. This can be done with this import statement:

import numpy as np

Getting the floor value

The greatest integer that is less than or equal to x where x is the array element is known as floor value. It can found using the function numpy.floor()

Syntax:

numpy.floor(x[, out]) = ufunc ‘floor’) 

Example 1: 

Output: 

[1.]

Example 2:

OutPut: 

[-2., -2., -1., 0., 1., 1., 3.]

Getting the ceil value

The least integer that is greater than or equal to x where x is the array element is known as ceil value. It can be found using the numpy.ceil() method.

Syntax:

numpy.ceil(x[, out]) = ufunc ‘ceil’) 

Example 1:

Output: 

[2.]

Example 2:

Output:

[-1., -1., -0., 1., 2., 2., 3.]

Getting the Truncate value

The trunc of the scalar x is the nearest integer i which, closer to zero than x. This simply means that, the fractional part of the signed number x is discarded by this function. It can be found using the numpy.trunc() method.

Syntax:

numpy.trunc(x[, out]) = ufunc ‘trunc’)

Example 1:

Output:

[1.]

Example 2:

Output:

[-1., -1., -0., 0., 1., 1., 3.]

Example to get floor, ceil, trunc values of the elements of a numpy array

Output:

[-1.8 -1.6 -0.5 0.5 1.6 1.8 3. ]

Floor values : 
 [-2. -2. -1. 0. 1. 1. 3.]

Ceil values : 
 [-1. -1. -0. 1. 2. 2. 3.]

Truncated values : 
 [-1. -1. -0. 0. 1. 1. 3.]
Comment