Return the ceil of the inputs in Numpy


To return the ceil of the input, use the numpy.ceil() method in Python Numpy. The ceil of the scalar x is the smallest integer i, such that i >= x. It is often denoted as $\mathrm{\lceil X \rceil}$. The function returns the ceil of each element in x, with float dtype. This is a scalar if x is a scalar.

The out is a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.

Steps

At first, import the required library −

import numpy as np

To return the ceil of the input, use the numpy.ceil() method in Python Numpy

Check ceil() for float −

print("Result? ", np.ceil(55.8))
print("
Result? ", np.ceil(-599.2))

Check ceil() for inf −

print("
Result? ", np.ceil(-np.inf))

Check ceil() for nan and inf −

print("
Result? ", np.ceil(np.nan)) print("
Result? ", np.ceil(np.inf))

Check ceil() for log −

print("
Result? ", np.ceil(np.log(1))) print("
Result? ", np.ceil(np.log(2)))

Example

import numpy as np

# To return the ceil of the input, use the numpy.ceil() method in Python Numpy
print("Returning the ceil value...
") # Check ceil() for float print("Result? ", np.ceil(55.8)) print("
Result? ", np.ceil(-599.2)) # Check ceil() for inf print("
Result? ", np.ceil(-np.inf)) # Check ceil() for nan and inf print("
Result? ", np.ceil(np.nan)) print("
Result? ", np.ceil(np.inf)) # Check ceil() for log print("
Result? ", np.ceil(np.log(1))) print("
Result? ", np.ceil(np.log(2)))

Output

Returning the ceil value...

Result? 56.0

Result? -599.0

Result? -inf

Result? nan

Result? inf

Result? 0.0

Result? 1.0

Updated on: 08-Feb-2022

527 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements