The numpy.ceil() function is used to return the ceil of the elements of an array. The ceil value of any scalar value x is the smallest integer i in a way such that i >= x. For example, the ceil value for 5.6 will be 6. In simpler words we can say, the nearest larger integer value is the ceil value.
Syntax of numpy.ceil():
Below we have a required syntax to use this function:
numpy.ceil(array)
Note: In the above syntax, the parameter array is used to indicate the array elements whose ceil values are to be calculated.
Returned Values:
This method will return an array containing the ceil values.
Now it’s time to cover some examples related to this method.
Example 1: Array with positive values
In the example given below, we will cover this method with positive values for an array and see the output:
import numpy as np
a = [1.90,2.3,0.6788]
y = np.ceil(a)
print("the output after applying ceil() is:")
print(y)
Output:
the output after applying ceil() is: [2. 3. 1.]
Example 2: Array with negative values
In this example, we will check the output if an array contains negative values. When we find the ceil value for a negative number, then the larger integer number for let’s say -1.9 will not be -2, but it will be -1. Because -1 is a larger value than -1.9, whereas -2 is less than -1.9 value.
The code snippet for the same is as follows:
import numpy as np
a = [-1.90,-2.3,-0.6788,12.34]
y = np.ceil(a)
print("the output after applying ceil() is:")
print(y)
Output:
the output after applying ceil() is: [-1. -2. -0. 13.]
