NumPy function floor_divide() in Python
The NumPy function floor_divide() used to compute the largest integer smaller or equal to the division of the inputs. It is equivalent to // operator and pairs with the Python % (remainder). It returns an array or scalar after computing the largest integer smaller or equal to the division, ie. y = floor(x1/x2). If x1 and x2 is scalar, it returns scalar.
Syntax
 1 numpy.floor_divide(x1, x2, /, out = None, *, where = True, casting = 'same_kind',
 2  order = 'K', dtype = None, subok = True[, signature, extobj]) = <ufunc 'floor_divide'>
x1 : it is scalar or an ndarray that act as numerator.
x2 : it is scalar or an ndarray that act as denominator. If x1.shape != x2.shape, they must be broadcastable to a common shape
out : It can be tuple of ndarray and None that specifies the location where the result will be stored. It is optional. If specified, it must have the same shape of source array. If not specified or None, it returns a freshly-allocated array.
where : It specifies the conditional expression or an array that specifies which elements should be includes in the resulting array.
dtype : It specifies the data type of the resulting array, if specified, otherwise None.
floor_divide() function
 1 import numpy as np
 2 
 3 res1 = np.floor_divide(4, 3)
 4 print('The floor divide is :', res1)
 5 
 6 arr1 = np.array([4, 6, 9])
 7 arr2 = np.array([3, 4, 4])
 8 res2 = np.floor_divide(arr1, arr2)
 9 print('The floor divide values are :', res2)
In the above example, a floor_divide() function is called by specifying scalar value and an array that compute the the largest integer smaller or equal to the division of the inputs. The result is assign to the variable that will be printed on console.
Output
 1 The floor divide is : 1
 2 The floor divide values are : [1 1 2]

Example 2

Example 2
 1 import numpy as np
 2 
 3 res1 = np.floor_divide(3, 3)
 4 print('The floor divide is :', res1)
 5 
 6 arr1 = np.array([5, 4, 3])
 7 arr2 = np.array([10, 3, 2])
 8 res2 = np.floor_divide(arr1, arr2)
 9 print('The floor divide values are :', res2)
In the above example, a floor_divide() function is called by specifying scalar value and an array that compute the the largest integer smaller or equal to the division of the inputs. The result is assign to the variable that will be print.
Output
 1 The floor divide is : 1
 2 The floor divide values are : [0 1 1]
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us