# Return the floor of the input in Numpy

NumpyServer Side ProgrammingProgramming

#### Python Data Science basics with Numpy, Pandas and Matplotlib

Most Popular

63 Lectures 6 hours

#### Data Analysis using NumPy and Pandas

19 Lectures 8 hours

#### Numpy with Python

Most Popular

12 Lectures 3 hours

To return the floor of the input, use the numpy.floor() method in Python Numpy. The floor of the scalar x is the largest integer i, such that i <= x. It is often denoted as $\mathrm{\lfloor X \rfloor}$. The function returns the floor of each element in x. This is a scalar if x is a scalar.

The out is a location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs.

## Steps

At first, import the required library −

import numpy as np

To return the floor of the input, use the numpy.floor() method in Python Numpy.

Check floor() for float −

print("Result? ", np.floor(45.7))
print("\nResult? ", np.floor(-487.4))

Check floor() for inf −

print("\nResult? ", np.floor(-np.inf))


Check floor() for nan and inf −

print("\nResult? ", np.floor(np.nan))
print("\nResult? ", np.floor(np.inf))

Check floor() for log −

print("\nResult? ", np.floor(np.log(1)))
print("\nResult? ", np.floor(np.log(2)))

## Example

import numpy as np

# To return the floor of the input, use the numpy.floor() method in Python Numpy
print("Returning the floor value...\n")

# Check floor() for float
print("Result? ", np.floor(45.7))
print("\nResult? ", np.floor(-487.4))

# Check floor() for inf
print("\nResult? ", np.floor(-np.inf))

# Check floor() for nan and inf
print("\nResult? ", np.floor(np.nan))
print("\nResult? ", np.floor(np.inf))

# Check floor() for log
print("\nResult? ", np.floor(np.log(1)))
print("\nResult? ", np.floor(np.log(2)))

## Output

Returning the floor value...

Result? 45.0

Result? -488.0

Result? -inf

Result? nan

Result? inf

Result? 0.0

Result? 0.0