如何使用numpy读取二进制文件的一部分?

如何使用numpy读取二进制文件的一部分?,第1张

如何使用numpy读取二进制文件的一部分?

您可以按正常方式对文件对象使用seek,然后在中使用此文件对象

fromfile
。这是一个完整的示例

import numpy as npimport osdata = np.arange(100, dtype=np.int)data.tofile("temp")  # save the dataf = open("temp", "rb")  # reopen the filef.seek(256, os.SEEK_SET)  # seekx = np.fromfile(f, dtype=np.int)  # read the data into numpyprint x # [64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88# 89 90 91 92 93 94 95 96 97 98 99]


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5661750.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存