Python | Numpy ndarray .__ imod __ ()

With Numpy ndarray .__ imod __ () every element in the array works with a binary operator, i.e. mod (%). Remember that we can use any type of value in the array, and the value for mod is applied as a parameter in ndarray .__ imod __ () .

Syntax: ndarray .__ imod __ ($ self, value, /)

Return: self% = value

Example No. 1:
In this example, we can see that the value we passed through ndarray .__ imod __ () is used to perform a mod operation on each element of the array.

# import an important module into python

import numpy as np

 
# make an array with NumPy

gfg = np.array ([ 1 , 2.5 , 3 , 4.8 , 5 ])

 
# applying the ndarray .__ imod __ () method

print (gfg .__ imod __ ( 2 ))

Exit:

 [1. 0.5 1. 0.8 1.] 

Example # 2:

# import important module in python

import numpy as np

 
# make mac with NumPy

gfg = np. array ([[ 1 , 2 , 3 , 4.45 , 5 ],

[ 6 , 5.5 , 4 , 3 , 2.62 ]])

 
# applying the ndarray method .__ imod __ ()

print (gfg .__ imod __ ( 3 ))

Exit:

 [[1. 2. 0. 1.45 2.] [0. 2.5 1. 0. 2.62]]