NumPy floor()

The numpy.floor() function rounds each element of an array down to the nearest integer. It returns the largest integer less than or equal to each element in the input.

Syntax

</>
Copy
numpy.floor(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True)

Parameters

ParameterTypeDescription
xarray_likeInput array whose elements will be floored.
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 apply the floor function to.
castingstr, optionalDefines how casting should behave.
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 where each element is rounded down to the nearest integer. If the input is a scalar, a scalar is returned.


Examples

1. Applying floor to a Single Value

Here, we compute the floor of a single floating-point value.

</>
Copy
import numpy as np

# Define a floating-point number
num = 3.7

# Apply the floor function
result = np.floor(num)

# Print the result
print("Floor of 3.7:", result)

Output:

Floor of 3.7: 3.0