Return the array data as a string containing the raw bytes in the array. The array is filled with a fill value before the string conversion. .. versionadded:: 1.9.0 Parameters ---------- fill_value : scalar, optional Value used to fill
(self, fill_value=None, order='C')
| 6166 | return self.tobytes(fill_value, order=order) |
| 6167 | |
| 6168 | def tobytes(self, fill_value=None, order='C'): |
| 6169 | """ |
| 6170 | Return the array data as a string containing the raw bytes in the array. |
| 6171 | |
| 6172 | The array is filled with a fill value before the string conversion. |
| 6173 | |
| 6174 | .. versionadded:: 1.9.0 |
| 6175 | |
| 6176 | Parameters |
| 6177 | ---------- |
| 6178 | fill_value : scalar, optional |
| 6179 | Value used to fill in the masked values. Default is None, in which |
| 6180 | case `MaskedArray.fill_value` is used. |
| 6181 | order : {'C','F','A'}, optional |
| 6182 | Order of the data item in the copy. Default is 'C'. |
| 6183 | |
| 6184 | - 'C' -- C order (row major). |
| 6185 | - 'F' -- Fortran order (column major). |
| 6186 | - 'A' -- Any, current order of array. |
| 6187 | - None -- Same as 'A'. |
| 6188 | |
| 6189 | See Also |
| 6190 | -------- |
| 6191 | numpy.ndarray.tobytes |
| 6192 | tolist, tofile |
| 6193 | |
| 6194 | Notes |
| 6195 | ----- |
| 6196 | As for `ndarray.tobytes`, information about the shape, dtype, etc., |
| 6197 | but also about `fill_value`, will be lost. |
| 6198 | |
| 6199 | Examples |
| 6200 | -------- |
| 6201 | >>> x = np.ma.array(np.array([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]]) |
| 6202 | >>> x.tobytes() |
| 6203 | 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' |
| 6204 | |
| 6205 | """ |
| 6206 | return self.filled(fill_value).tobytes(order=order) |
| 6207 | |
| 6208 | def tofile(self, fid, sep="", format="%s"): |
| 6209 | """ |