Python | Numpy numpy.ndarray .__ mod __ ()



With Numpy numpy.ndarray .__ mod __ () 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 .__ mod __ () .

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

Return: self% value

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

# import important module in python

import numpy as np

 
# make an array with NumPy

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

 
# application method ndarray .__ mod __ ()

print (gfg .__ mod __ ( 2 ))

Exit :

 [1. 0.5 1. 0.8 1.] 

Example # 2:

# import important module in python

import numpy as np

  
# make an array with Nu mPy

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

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

 
# applying the ndarray method .__ mod __ ()

print (gfg .__ mod __ (  3 ))

Exit :

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