[ Web Proxy ]
URL:
Viewing: https://numpy.org/doc/stable/reference/generated/../generated/numpy.ma.MaskedArray.tobytes.html [Back]  [Original]

numpy.ma.MaskedArray.tobytes — NumPy v2.5 Manual
Back to top
Search the docs ...:

numpy.ma.MaskedArray.tobytes#

method

ma.MaskedArray.tobytes(fill_value=None, order='C')[source]#

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.

Parameters:
fill_valuescalar, optional

Value used to fill in the masked values. Default is None, in which case MaskedArray.fill_value is used.

order{C,F,A}, optional

Order of the data item in the copy. Default is C.

  • C C order (row major).

  • F Fortran order (column major).

  • A Any, current order of array.

  • None Same as A.

Notes

As for ndarray.tobytes, information about the shape, dtype, etc., but also about fill_value, will be lost.

Examples

Try it in your browser!
>>> import numpy as np
>>> 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'

Web Proxy Viewer  |  New URL  |  Original Page