Open In App

numpy.floor() in Python

Last Updated : 08 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

  • x: Input array (array-like)

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy