Friday, September 19, 2025
HomeLanguagesNumpy MaskedArray.dot() function | Python

Numpy MaskedArray.dot() function | Python

numpy.MaskedArray.dot() function is used to calculate the dot product of two mask arrays.

Syntax : numpy.ma.dot(arr1, arr2, strict=False)

Parameters:
arr1, arr2:[ ndarray] Inputs arrays.
strict : [bool, optional] Whether masked data are propagated (True) or set to 0 (False) for the computation. Default is False.

Return : [ ndarray] The dot product of arr1 and arr2.

Code #1 :




# Python program explaining
# numpy.MaskedArray.dot() method 
    
# importing numpy as geek  
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma 
    
# creating input arrays   
in_arr1 = geek.array([[1, 2], [ 3, 4]])
print ("1st Input array : ", in_arr1) 
    
in_arr2 = geek.array([[-1, -2], [ -3, -4]]) 
print ("2nd Input array : ", in_arr2) 
    
      
# Now we are creating  masked array.  
# by making  entry as invalid   
mask_arr1 = ma.masked_array(in_arr1, mask = [[ 1, 0], [ 0, 1]])  
print ("1st Masked array : ", mask_arr1) 
    
mask_arr2 = ma.masked_array(in_arr2, mask =[[ 0, 1], [ 0, 0]])  
print ("2nd Masked array : ", mask_arr2) 
    
# applying MaskedArray.dot methods  
# to masked array  
out_arr = ma.dot(mask_arr1, mask_arr2)  
print ("Dot product of two arrays : ", out_arr)      


Output:

1st Input array :  [[1 2]
 [3 4]]
2nd Input array :  [[-1 -2]
 [-3 -4]]
1st Masked array :  [[-- 2]
 [3 --]]
2nd Masked array :  [[-1 --]
 [-3 -4]]
Dot product of two arrays :  [[-6 -8]
 [-3 --]]

 

Code #2 :




# Python program explaining
# numpy.MaskedArray.dot() method 
    
# importing numpy as geek  
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma 
    
# creating input arrays   
in_arr1 = geek.array([[1, 2], [ 3, -1], [ 5, -3]])
print ("1st Input array : ", in_arr1) 
    
in_arr2 = geek.array([[1, 0, 3], [ 4, 1, 6]]) 
print ("2nd Input array : ", in_arr2) 
    
      
# Now we are creating  masked array.  
# by making  entry as invalid   
mask_arr1 = ma.masked_array(in_arr1, mask = [[ 1, 0], [ 0, 1], [ 0, 0]])  
print ("1st Masked array : ", mask_arr1) 
    
mask_arr2 = ma.masked_array(in_arr2, mask =[[ 0, 0, 0], [ 0, 0, 1]])  
print ("2nd Masked array : ", mask_arr2) 
    
# applying MaskedArray.dot methods  
# to masked array  
out_arr = ma.dot(mask_arr1, mask_arr2)  
print ("Dot product of two arrays : ", out_arr)      


Output:

1st Input array :  [[ 1  2]
 [ 3 -1]
 [ 5 -3]]
2nd Input array :  [[1 0 3]
 [4 1 6]]
1st Masked array :  [[-- 2]
 [3 --]
 [5 -3]]
2nd Masked array :  [[1 0 3]
 [4 1 --]]
Dot product of two arrays :  [[8 2 --]
 [3 0 9]
 [-7 -3 15]]

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32301 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6665 POSTS0 COMMENTS
Nicole Veronica
11840 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11898 POSTS0 COMMENTS
Shaida Kate Naidoo
6781 POSTS0 COMMENTS
Ted Musemwa
7056 POSTS0 COMMENTS
Thapelo Manthata
6739 POSTS0 COMMENTS
Umr Jansen
6744 POSTS0 COMMENTS