NumPy ceil()
The numpy.ceil() function returns the ceiling value of each element in an input array.
The ceiling of a number is the smallest integer greater than or equal to that number.
Syntax
</>
Copy
numpy.ceil(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)
Parameters
| Parameter | Type | Description |
|---|---|---|
x | array_like | Input array containing numerical values. |
out | ndarray, None, or tuple of ndarray and None, optional | Optional output array where the result is stored. If None, a new array is created. |
where | array_like, optional | Boolean mask specifying which elements to compute. Elements where where=False retain their original value. |
casting | str, optional | Defines the casting behavior when computing the ceiling function. |
order | str, optional | Memory layout order of the output array. |
dtype | data-type, optional | Defines the data type of the output array. |
subok | bool, optional | Determines if subclasses of ndarray are preserved in the output. |
Return Value
Returns an array with the ceiling values of the input elements. If the input is a scalar, a scalar is returned.
Examples
1. Computing the Ceiling of a Single Value
Here, we compute the ceiling of a single floating-point number.
</>
Copy
import numpy as np
# Define a floating-point number
num = 3.7
# Compute the ceiling of the number
result = np.ceil(num)
# Print the result
print("Ceiling of 3.7:", result)
Output:
Ceiling of 3.7: 4.0
