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

NumPy · Function

np.floor

Returns the mathematical floor of input values element-wise: the greatest integer less than or equal to each value. It returns an ndarray for array input and a scalar for scalar input.

How it works

np.floor is a universal function that applies the mathematical floor independently to each input element. For every value, it selects the greatest integer that is less than or equal to that value; array input produces an array, while scalar input produces a scalar.

Syntax

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

Parameters

NameTypeDescription
xarray_likeInput data.
outndarray, None, or tuple of ndarray and None, optionalDestination in which the result is stored; may be an ndarray, None, or a tuple of ndarray and None.
wherearray_like of bool, optionalCondition broadcast over the input; where false, the output is not computed.
casting{‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optionalControls the data-type casting permitted for the operation.
order{‘K’, ‘A’, ‘C’, ‘F’}, optionalControls the memory layout of the result.
dtypedtype, optionalData type of the returned result.
subokbool, optionalIf true, subclasses of ndarray are passed through.
signaturestr or tuple of ints, optionalGeneralized ufunc signature, when applicable.

Returns

ndarray or scalar: the floor of each element in x; a scalar if x is a scalar.

Key points

  • Computes floor independently for every input element.
  • For a value x, the result is the greatest integer that does not exceed x.
  • The operation has the standard mathematical notation ⌊x⌋.
  • The optional out argument can store results in a supplied destination.
  • The returned array contains one floored result for each input element.

Common mistakes

  • Flooring is not truncation toward zero: negative fractional values move to the next smaller integer.

Example: Floor an array element-wise

import numpy as np

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

Applies floor element-wise, including rounding negative nonintegers toward smaller values.

When to use it

Lower-bound binning

Convert continuous measurements into lower integer-valued bins.

Vectorized preprocessing

Apply a mathematical lower bound to every value in an ndarray without writing an explicit loop.

Masked or in-place-style output

Reuse an existing destination array or restrict updates with ufunc output controls.

Interview questions

QWhat does np.floor compute?

np.floor returns the floor of its input element-wise. For each scalar, that is the largest integer less than or equal to the value.

Follow-up: How does it behave for a scalar input? It returns a scalar rather than a one-element array.

QWhat are the input and output forms?

The function accepts array-like input and returns the floor of every element. An array input yields an ndarray, whereas a scalar input yields a scalar.

Follow-up: What happens with negative values? A value such as -0.2 becomes -1, because -1 is the greatest integer no larger than -0.2.

QHow can computation be directed or selectively applied?

As a ufunc, np.floor supports an optional out destination and a where mask in addition to the input. These enable selective computation and storage into a supplied array.

Follow-up: Why use where with out? Unselected positions can retain their preexisting destination values instead of being recalculated.

  • numpy.ceil
  • numpy.trunc
  • numpy.rint

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