numpy.recarray.tobytes#

方法

recarray.tobytes(order='C')#

构建包含数组原始数据字节的 Python bytes 对象。

构建一个显示数据内存原始内容副本的 Python bytes 对象。默认情况下,bytes 对象以 C 顺序生成。此行为由 order 参数控制。

参数:
order{‘C’, ‘F’, ‘A’}, optional

控制 bytes 对象的内存布局。‘C’ 表示 C 顺序,‘F’ 表示 F 顺序,‘A’(*Any* 的缩写)表示如果 a 是 Fortran 连续的,则为‘F’,否则为‘C’。默认为‘C’。

返回:
sbytes

显示 a 原始数据副本的 Python bytes 对象。

另请参阅

frombuffer

此操作的逆操作,从 Python bytes 构建一个一维数组。

示例

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