Python | Numpy MaskedArray .__ rand__

Arrays | NumPy | Python Methods and Functions

numpy.ma.MaskedArray class is a subclass of ndarray for manipulating numeric arrays with missing data. With the Numpy method MaskedArray .__ rand__ we can get the elements that are added as a value as a parameter.

Syntax: numpy. MaskedArray .__ rand__

Return: Return value & amp; self.

Example # 1:
In this example, we can see that each element has a value passed as a parameter.

 
# import an important module into python

import numpy as np 

 
# make an array with NumPy

gfg = np.ma.array ([ 1 , 2 , 3 , 4 , 5 ]) 

 
# applying MaskedArray .__ rand __ () method

print (gfg .__ rand __ ( 2 )) 

Output:

 [0 2 2 0 0] 

Example # 2:

# import an important module into python

import numpy as np 

 
# make an array with NumPy

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

[ 6 , 5 , 4 , 3 , 2 ]]) 

 
# applying MaskedArray .__ rand __ () method

print (gfg .__ rand __ ( 1 )) 

Exit:

 [[1 0 1 0 1] [0 1 0 1 0]] 




Get Solution for free from DataCamp guru