SciPy

numpy.ndarray.tostringΒΆ

ndarray.tostring(order='C')ΒΆ

Construct Python bytes containing the raw data bytes in the array.

Constructs Python bytes showing a copy of the raw contents of data memory. The bytes object can be produced in either β€˜C’ or β€˜Fortran’, or β€˜Any’ order (the default is β€˜C’-order). β€˜Any’ order means C-order unless the F_CONTIGUOUS flag in the array is set, in which case it means β€˜Fortran’ order.

This function is a compatibility alias for tobytes. Despite its name it returns bytes not strings.

Parameters:
order : {β€˜C’, β€˜F’, None}, optional

Order of the data for multidimensional arrays: C, Fortran, or the same as for the original array.

Returns:
s : bytes

Python bytes exhibiting a copy of a’s raw data.

Examples

>>> x = np.array([[0, 1], [2, 3]])
>>> x.tobytes()
b'\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00'
>>> x.tobytes('C') == x.tobytes()
True
>>> x.tobytes('F')
b'\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00'

Previous topic

numpy.ndarray.tolist

Next topic

numpy.ndarray.trace