fill_value}") # 计算有效数据的平均值 mean_value = masked_data1.mean() print(f"有效数据的平均值: {mean_value}") 2.17.2 运算传播规则 处理masked_array 时,运算会根据掩码数组的规则传播。例如,如果两个 masked_array 相加,任何一个操作数的无效元素都会导致结果中对应位置的元素也无效。 基本运算...
numpy.MaskedArray.allequal()函数如果a和b的所有条目都相等,则返回True,使用fill_value作为真值,其中任何一个或两个都被屏蔽。 语法:numpy.ma.allequal(arr1, arr2, fill_value=True) 参数: arr1, arr2 :[array_like] 要比较的输入数组。 fill_value :[ bool, optional] arr1或arr2中的屏蔽值是否被视...
>>>x = np.ma.array([0,1.], fill_value=-np.inf)>>>x.fill_value -inf>>>x.fill_value = np.pi>>>x.fill_value3.1415926535897931# may vary 重置为默认值: >>>x.fill_value =None>>>x.fill_value1e+20 ma.MaskedArray.baseclass 底层数据的类(只读)。 ma.MaskedArray.sharedmask 掩码的...
mask)] masked_array(data = [-999.0 51.0 79.0 57.0 97.0 98.0 74.0 52.0], mask = [False False False False False False False False], fill_value = 1e+20) 指定掩膜和去掩膜 在创建掩膜数组时,如果需要对指定索引的数据进行掩膜,可以不需要利用条件掩膜函数,而通过 numpy.ma 模块中的 masked 常数...
masked_array(data = [-- -- -- 5 7 -- -- -- 8 --], mask = [ True True True False False True True True False True], fill_value = 999999) 掩码数组具有三个属性:data、mask、fill_value;data表示原始数值数组>,mask表示获得掩码用的布尔数组,fill_value表示的填充值替代无效值之>后的数组...
maskedarray:处理(传播)缺失数据 1. # 对于花式,人们可以使用NaN,但是面具适用于所有类型: x = np.ma.array([1, 2, 3, 4], mask=[0, 1, 0, 1]) x # masked_array(data = [1 -- 3 --],mask = [False True False True],fill_value = 999999) ...
Python numpy.ma.MaskedArray.tolist()函数 numpy.ma.MaskedArray.tolist()函数将屏蔽数组的数据部分作为一个分层的Python列表返回。 语法: numpy.ma.MaskedArray.tolist(fill_value = None) 参数 : fill_value : [标量,可选] 无效条目使用的值。默认为无。 返回 :
masked array using the regular array and the mask masked_array = np.ma.masked_array(data, mask=mask) # Fill the masked values with a specified number (e.g., -1) filled_array = np.ma.filled(masked_array, fill_value=-1) # Print the original masked array and the filled array print(...
While both chains of item access result in a new masked array of the shape of the array-valued field, they have different.fill_values; the first form results in a.fill_valuewhich: Is array-valued, which does not seem consistent with masked arrays usually behaves, and Neglects the.fill_va...
MaskedArray作为numpy.ndarray的子类,继承了numpy.ndarray索引、切片、广播、形状操纵的机制。但在通用函数和比较操作时有所不同,MaskedArray会忽略掩码,因此使用掩码数组时无需考虑无效值。 In [8]: mx.mean() Out[8]: 0.6666666666666666 In [9]: mx > 1 Out[9]: masked_array(data=[False, True, --, ...