Python | Numpy ndarray.__ifloordiv__()

Python | Numpy ndarray.__ifloordiv__()

In NumPy, the ndarray.__ifloordiv__() method corresponds to the in-place floor division operation //=. It modifies the calling ndarray by performing element-wise floor division with another array or scalar.

Here's what you need to know about ndarray.__ifloordiv__():

  • It applies floor division on elements.
  • After the operation, the original array gets modified to store the result.

Let's go through some examples:

Example 1: Using //= operator with ndarrays

import numpy as np # Creating two arrays a = np.array([10.5, 25.6, 32.9, 45.5]) b = np.array([2, 4, 8, 2]) # Performing in-place floor division a //= b print(a) # Output: [ 5. 6. 4. 22.] 

Example 2: Using __ifloordiv__() method directly with ndarray and scalar

import numpy as np # Creating an array a = np.array([10.5, 25.6, 32.9, 45.5]) # Performing in-place floor division a.__ifloordiv__(4) print(a) # Output: [ 2. 6. 8. 11.] 

In both examples, the original array a gets modified to store the result of the floor division.


More Tags

endpoint tui bi-publisher itoa cors primeng-turbotable postgresql blank-line checkstyle looker-studio

More Programming Guides

Other Guides

More Programming Examples