python 将二进制文件直接读取成字节数组
读取:np.fromfile(frame, dtype=np.float, count=‐1, sep='')
frame
: 文件、字符串dtype
: 读取的数据类型count
: 读入元素个数,‐1表示读入整个文件sep
: 数据分割字符串,如果是空串,写入文件为二进制
self.mirrorFileData = np.fromfile(self.lineEdit_mirror.text(), dtype='uint8',
count=-1) #os.path.getsize(self.lineEdit_mirror.text())
存储:
a.tofile(frame, sep='', format='%s')
frame
: 文件、字符串sep
: 数据分割字符串,如果是空串,写入文件为二进制format
: 写入数据的格式
a = np.array(50).reshape(5,5,2)
a.tofile("b.bat", sep = ",", format = "%d")