📜  Python| numpy numpy.ndarray.__floordiv__()(1)

📅  最后修改于: 2023-12-03 15:04:21.130000             🧑  作者: Mango

Python | numpy numpy.ndarray.floordiv()
Introduction

The numpy.ndarray.__floordiv__() method performs element-wise floor division of two arrays.

Syntax
numpy.ndarray.__floordiv__(self, value, /, out=None, *, where=True, casting='same_kind', **kwargs)
Parameters
  • self: array_like The array to be divided element-wise.
  • value: array_like or scalar The divisor. It may be a scalar or an array, but must have the same shape as self.
  • out: ndarray, optional A location into which the result is stored.
  • where: array_like, optional A boolean array which is broadcasted to match the dimensions of self, and selects elements to operate on.
  • casting: {‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’}, optional Controls what kind of data casting may occur.
Return Value

Returns the floor division of self and value, i.e., self // value.

Example
import numpy as np

a = np.array([10, 20, 30, 40])
b = np.array([3, 5, 7, 9])

print(np.floor_divide(a, b))

Output:

array([3, 4, 4, 4])
Conclusion

The numpy.ndarray.__floordiv__() method is an efficient way to perform element-wise floor division of two arrays. It returns a new array containing the floor division of the two input arrays.