numpy.floor() in Python (original) (raw)

Last Updated : 08 Apr, 2025

The **numpy.floor() function returns the **largest integer less than or equal to each element in the input array. It effectively rounds numbers down to the **nearest whole number. Let’s understand with an example:

Python `

import numpy as np

a = [0.5, 1.5, 2.5, 3, 4.5, 10.1]

res = np.floor(a) print("Floored:", res)

`

Output

Floored: [ 0. 1. 2. 3. 4. 10.]

**Explanation: **np.floor() function reduces every element of the array **‘a’ to its floor value.

Syntax

numpy.floor(x)

**Parameters:

**Return Type: Array with the floor of each element (as floats)

Examples of numpy.floor()

Example 1: With Decimal Values

Python `

import numpy as np

a = [0.53, 1.54, 0.71] print("Input:", a)

res = np.floor(a) print("Floored:", res)

`

Output

Input: [0.53, 1.54, 0.71] Floored: [0. 1. 0.]

Example 2: Precise Decimal Inputs

Python `

import numpy as np

a = [0.5538, 1.33354, 0.71445] print("Input:", a)

res = np.floor(a) print("Floored:", res)

`

Output

Input: [0.5538, 1.33354, 0.71445] Floored: [0. 1. 0.]

Example 3: Mixed Whole and Decimal Numbers

Python `

import numpy as np

a = [1.67, 4.5, 7, 9, 12] print("Input:", a)

res = np.floor(a) print("Floored:", res)

`

Output

Input: [1.67, 4.5, 7, 9, 12] Floored: [ 1. 4. 7. 9. 12.]

Similar Reads