Syntax error Return the floor of the input in Numpy

Return the floor of the input in Numpy



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("
Result? ", np.floor(-487.4))

Check floor() for inf −

print("
Result? ", np.floor(-np.inf))

Check floor() for nan and inf −

print("
Result? ", np.floor(np.nan)) print("
Result? ", np.floor(np.inf))

Check floor() for log −

print("
Result? ", np.floor(np.log(1))) print("
Result? ", 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...
") # Check floor() for float print("Result? ", np.floor(45.7)) print("
Result? ", np.floor(-487.4)) # Check floor() for inf print("
Result? ", np.floor(-np.inf)) # Check floor() for nan and inf print("
Result? ", np.floor(np.nan)) print("
Result? ", np.floor(np.inf)) # Check floor() for log print("
Result? ", np.floor(np.log(1))) print("
Result? ", 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
Updated on: 2022-02-08T07:35:13+05:30

201 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements