📜  Python| numpy numpy.ndarray.__floordiv__()

📅  最后修改于: 2022-05-13 01:54:37.533000             🧑  作者: Mango

Python| numpy numpy.ndarray.__floordiv__()

Numpy numpy.ndarray.__floordiv__()的帮助下,可以划分在ndarray.__floordiv__()方法中作为参数提供的特定值。值将被划分为numpy 数组中的每个元素,并记住它总是给出除法后的底值

示例 #1:
在这个例子中,我们可以看到数组中的每个元素都用ndarray.__floordiv__()方法中作为参数给出的值进行划分,并给出数组中每个元素的下限值。此方法适用于数组的正值、负值和浮点值。

# import the important module in python
import numpy as np
   
# make an array with numpy
gfg = np.array([1, 2.5, 3, 4.8, 5])
   
# applying ndarray.__floordiv__() method
print(gfg.__floordiv__(2))
输出:
[ 0.  1.  1.  2.  2.]

示例 #2:

# import the important module in python
import numpy as np
   
# make an array with numpy
gfg = np.array([[1, 2, 3, 4.45, 5],
                [6, 5.5, 4, 3, 2.62]])
   
# applying ndarray.__floordiv__() method
print(gfg.__floordiv__(3))
输出:
[[ 0.  0.  1.  1.  1.]
 [ 2.  1.  1.  1.  0.]]