NumPy参考 >数组对象 >Masked arrays >Constants of the numpy.ma module > numpy.ma.MaskedArray.tobytes
方法
MaskedArray.
tobytes
(self,fill_value = None,order ='C' )[源代码] ¶将数组数据作为包含数组中原始字节的字符串返回。
在字符串转换之前,用填充值填充数组。
1.9.0版中的新功能。
用于填充掩码值的值。默认为无,在这种情况下MaskedArray.fill_value
使用。
副本中数据项的顺序。默认值为“ C”。
'C'-C顺序(行主要)。
'F'– Fortran订单(主要列)。
'A'–数组的任何当前顺序。
无–与“ A”相同。
笔记
至于ndarray.tobytes,有关形状,dtype等以及有关的信息fill_value
将丢失。
例子
>>> x = np.ma.array(np.array([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]])
>>> x.tobytes()
b'\x01\x00\x00\x00\x00\x00\x00\x00?B\x0f\x00\x00\x00\x00\x00?B\x0f\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00'