📅  最后修改于: 2023-12-03 15:34:15.029000             🧑  作者: Mango
The MaskedArray.__mod__()
method returns the element-wise remainder of the input array with respect to the second array, provided that these arrays have the same shape and the same mask.
The syntax of MaskedArray.__mod__()
method is:
numpy.MaskedArray.__mod__(self, other, fill_value=None)
Here, self
is the input array, other
is the second array, and fill_value
takes None as default value if not provided.
self: It represents the input array.
other: It represents the second array.
fill_value: It is an optional parameter that sets the value used to fill in the masked values in the input array.
The MaskedArray.__mod__()
method returns an array with the same shape as self/other, but with masked values in areas where either the self or other array has masked values.
import numpy as np
from numpy import ma
a = ma.array([1, 10, 3, 8, 17])
b = ma.array([3, 7, 8, 11, 9])
result = a % b
print("After a % b :")
print(result)
Output:
After a % b :
[1 3 3 8 --]
The above example shows that the MaskedArray.__mod__()
method calculates the element-wise remainder of the array a
with respect to the array b
and returns a masked array where there are missing values.
In conclusion, MaskedArray.__mod__()
method in Numpy module is used to calculate the element-wise remainder of the input array with respect to the second array while dealing with missing values in the input array.