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:
- 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
- numpy.floor_divide() in Python numpy.floor_divide(arr1, arr2, /, out = None, where = True, casting = 'same_kind', order = 'K', dtype = None) : Array element from first array is divided by the elements from second array(all happens element-wise). Both arr1 and arr2 must have same shape. It is equivalent to the Python // operator a 3 min read
- numpy.clip() in Python numpy.clip() function is used to Clip (limit) the values in an array. Given an interval, values outside the interval are clipped to the interval edges. For example, if an interval of [0, 1] is specified, values smaller than 0 become 0, and values larger than 1 become 1. Syntax : numpy.clip(a, a_min, 2 min read
- NumPy Array in Python NumPy (Numerical Python) is a powerful library for numerical computations in Python. It is commonly referred to multidimensional container that holds the same data type. It is the core data structure of the NumPy library and is optimized for numerical and scientific computation in Python. Table of C 2 min read
- numpy.gcd() in Python numpy.gcd(arr1, arr2, out = None, where = True, casting = ‘same_kind’, order = ‘K’, dtype = None) : This mathematical function helps user to calculate GCD value of |arr1| and |arr2| elements. Greatest Common Divisor (GCD) of two or more numbers, which are not all zero, is the largest positive number 1 min read
- numpy.around() in Python numpy.around(arr, decimals = 0, out = None) : This mathematical function helps user to evenly round array elements to the given number of decimals. Parameters : array : [array_like] Input array. decimal : [int, optional] Decimal places we want to round off. Default = 0. In case of -ve decimal, it sp 2 min read
- Python | Numpy ndarray.__ifloordiv__() With the help of Numpy ndarray.__ifloordiv__(), we can divide a particular value that is provided as a parameter in the ndarray.__ifloordiv__() method. Value will be divided to each and every element in a numpy array and remember it always gives the floor value after division. Syntax: ndarray.__iflo 1 min read
- numpy.greater() in Python The numpy.greater() checks whether x1 is greater than x2 or not. Syntax : numpy.greater(x1, x2[, out]) Parameters : x1, x2 : [array_like]Input arrays. If x1.shape != x2.shape, they must be broadcastable to a common shape out : [ndarray, boolean]Array of bools, or a single bool if x1 and x2 are scala 2 min read
- numpy.bincount() in Python In an array of +ve integers, the numpy.bincount() method counts the occurrence of each element. Each bin value is the occurrence of its index. One can also set the bin size accordingly. Syntax : numpy.bincount(arr, weights = None, min_len = 0) Parameters : arr : [array_like, 1D]Input array, having p 2 min read
- numpy.mod() in Python numpy.mod() is another function for doing mathematical operations in numpy.It returns element-wise remainder of division between two array arr1 and arr2 i.e. arr1 % arr2 .It returns 0 when arr2 is 0 and both arr1 and arr2 are (arrays of) integers. Syntax : numpy.mod(arr1, arr2, /, out=None, *, where 2 min read
- numpy.fromiter() function – Python NumPy's fromiter() function is a handy tool for creating a NumPy array from an iterable object. This iterable can be any Python object that provides elements one at a time. The function is especially useful when you need to convert data from a custom data source, like a file or generator, into a Num 2 min read