What is the numpy.floor_divide() function in Python?

Overview

The floor_divide() function in Python is used to return the largest integer <= to the division of the x1 and x2 inputs. The // operator in Python is equivalent to the floor_divide() function.

Syntax

numpy.floor_divide(x1, x2, out=None, where=True)

Parameters

Required

The floor_divide() function takes the following mandatory parameter values:

  • x1: Represents the numerator input.

  • x2: Represents the denominator input.

Optional

The floor_divide() function takes the following optional parameter values:

  • out: Represents the location where the result is stored.

  • where: Represents the condition that is broadcasted over the input.

Return value

The floor_divide() function returns the floor value of the (x1x2\frac{x1}{x2}). It will be a scalar value if both inputs are scalars.

Example

Let’s look at the example below:

import numpy as np
# creating my numerator and demominatorn inputs
x1 = np.arange(6) + 1
x2 = 2.5
# implementing the floor_divide() function
floorvalue = np.floor_divide(x1, x2)
print(floorvalue)

Explanation

  • Line 1: We import the numpy module.

  • Line 4: We create the numerator variable, x1.

  • Line 5: We create the denominator variable, x2.

  • Line 8: We implement the floor_divide() function on both variables. The result is assigned to a variable floorvalue.

  • Line 10: We print the variable floorvalue.

Free Resources