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

ParameterTypeDescription
xarray_likeInput array containing numerical values.
outndarray, None, or tuple of ndarray and None, optionalOptional output array where the result is stored. If None, a new array is created.
wherearray_like, optionalBoolean mask specifying which elements to compute. Elements where where=False retain their original value.
castingstr, optionalDefines the casting behavior when computing the ceiling function.
orderstr, optionalMemory layout order of the output array.
dtypedata-type, optionalDefines the data type of the output array.
subokbool, optionalDetermines 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