Numpy ndarray.tobytes()函数| Python
numpy.ndarray.tobytes()
函数构造包含数组中原始数据字节的Python字节。
Syntax : numpy.ndarray.tobytes(order=’C’)
Parameters :
order : [{‘C’, ‘F’, None}, optional] Order of the data for multidimensional arrays: C, Fortran, or the same as for the original array.
Return : Python bytes exhibiting a copy of arr’s raw data.
代码#1:
# Python program explaining
# numpy.ndarray.tobytes() function
# importing numpy as geek
import numpy as geek
arr = geek.array([[0, 1], [2, 3]], dtype ='
输出 :
b'\x00\x00\x01\x00\x02\x00\x03\x00'
代码#2:
# Python program explaining
# numpy.ndarray.tobytes() function
# importing numpy as geek
import numpy as geek
arr = geek.array([[0, 1], [2, 3]], dtype ='
输出 :
b'\x00\x00\x02\x00\x01\x00\x03\x00'