Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

NumPy · Function

np.ceil

Returns the ceiling of an input element-wise: each value becomes the smallest integer greater than or equal to it. Scalar inputs produce scalars; array inputs produce floating-point arrays.

How it works

np.ceil applies the mathematical ceiling element by element: each value becomes the smallest integer not less than that value. It accepts scalars or array-like inputs, returns a scalar for scalar input, and otherwise produces an array; results use floating-point dtype.

Syntax

numpy.ceil(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True [, signature])

Parameters

NameTypeDescription
xarray_likeInput value or array whose ceiling is computed.
outndarray, None, or tuple of ndarray and NoneOptional destination array for the result.
wherearray_like of boolBoolean mask selecting where computation occurs.
casting{'no', 'equiv', 'safe', 'same_kind', 'unsafe'}Controls permitted casting for the operation.
order{'K', 'A', 'C', 'F'}Memory layout order for the output.
dtypedtype, NoneOutput dtype.
subokboolWhether subclasses of ndarray are preserved.
signaturestring, NoneOptional generalized-ufunc signature.

Returns

ndarray or scalar: the ceiling of each element in x, with float dtype; scalar input produces a scalar.

Key points

  • The function applies ceiling independently to every input element.
  • For a value x, ceiling chooses the least integer that is at least x.
  • The mathematical notation for this operation is ⌈x⌉.
  • Scalar input yields scalar output.
  • Array results contain the element-wise ceilings using floating-point dtype.
  • Related rounding functions documented alongside np.ceil include floor, trunc, rint, and fix.

Common mistakes

  • Scalar input produces a scalar result rather than a one-element array.
  • Even when the mathematical results are whole numbers, the returned values use floating-point dtype.

Example: Element-wise ceiling of an array

import numpy as np

values = np.array([-1.7, -0.2, 0.2, 1.5])
print(np.ceil(values))
# [-1. -0.  1.  2.]

Rounds each array element upward to the smallest integer that is greater than or equal to it.

When to use it

Round requirements upward

Convert measured or computed quantities into conservative whole-unit requirements, such as allocating enough capacity for a fractional count.

Vectorized array rounding

Apply ceiling to every element of an ndarray without writing an explicit Python loop.

Controlled ufunc output

Use out or where when integrating the calculation into an existing array-processing pipeline.

Interview questions

QWhat does np.ceil compute, and how does it behave on arrays?

np.ceil is a NumPy universal function that returns the ceiling element-wise. For a scalar x, the result is the smallest integer i satisfying i >= x; for an array, the operation is applied independently to every element.

Follow-up: How does it differ from np.floor? ceil rounds toward positive infinity, whereas floor rounds toward negative infinity, so negative fractional values distinguish them.

QWhich important optional arguments does the signature expose?

The function accepts x plus optional ufunc controls such as out, where, casting, order, dtype, and subok. The out argument can be used to place results into a supplied output array.

Follow-up: What should be checked when using where with an output buffer? Ensure positions not selected by where are initialized if their values will be read, because they are not newly computed by the operation.

QWhat type of result should callers expect?

For a scalar input, np.ceil returns a scalar; for array input, it returns an array containing the ceiling of each element. The documented result has floating-point dtype.

Follow-up: Why can -0.2 display as -0.? IEEE floating-point represents signed zero, and ceiling preserves that representation in this case even though it compares equal to zero.

  • numpy.floor
  • numpy.trunc
  • numpy.rint
  • numpy.fix

Source: numpy.ceil — NumPy v2.5 Manual. Checked 2026-10-15.