Numpy MaskedArray.dot() function | Python (original) (raw)
Last Updated : 18 Oct, 2019
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 :
import
numpy as geek
import
numpy.ma as ma
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)
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)
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 :
import
numpy as geek
import
numpy.ma as ma
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)
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)
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]]
Similar Reads
- Numpy MaskedArray.anom() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 2 min read
- Numpy MaskedArray.all() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays. Masked arrays are arr 3 min read
- Numpy MaskedArray.any() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 3 min read
- Numpy MaskedArray.argsort() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 3 min read
- Numpy MaskedArray.astype() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 3 min read
- Numpy MaskedArray.flatten() function | Python numpy.MaskedArray.flatten() function is used to return a copy of the input masked array collapsed into one dimension. Syntax : numpy.ma.flatten(order='C') Parameters: order : [‘C’, ‘F’, ‘A’, ‘K’, optional] Whether to flatten in C (row-major), Fortran (column-major) order, or preserve the C/Fortran o 2 min read
- Numpy MaskedArray.cumprod() function | Python numpy.MaskedArray.cumprod() Return the cumulative product of the masked array elements over the given axis.Masked values are set to 1 internally during the computation. However, their position is saved, and the result will be masked at the same locations. Syntax : numpy.ma.cumprod(axis=None, dtype=N 3 min read
- Numpy MaskedArray.conjugate() function | Python numpy.MaskedArray.conjugate() function is used to return the complex conjugate, element-wise.The conjugate of a complex number is obtained by changing the sign of its imaginary part. Syntax : numpy.ma.conjugate(arr, out=None, where=True, casting='same_kind', order='K', dtype=None, subok=True)Paramet 2 min read
- Numpy MaskedArray.atleast_1d() function | Python numpy.MaskedArray.atleast_1d() function is used to convert inputs to masked arrays with at least one dimension.Scalar inputs are converted to 1-dimensional arrays, whilst higher-dimensional inputs are preserved. Syntax : numpy.ma.atleast_1d(*arys) Parameters: arys:[ array_like] One or more input arr 2 min read
- Numpy MaskedArray.atleast_2d() function | Python numpy.MaskedArray.atleast_2d() function is used to convert inputs to masked arrays with at least two dimension.Scalar and 1-dimensional arrays are converted to 2-dimensional arrays, whilst higher-dimensional inputs are preserved. Syntax : numpy.ma.atleast_2d(*arys) Parameters: arys:[ array_like] One 2 min read