python fromfile函数_Python numpy.core.records.fromfile函数方法的使用

numpy.core.records.fromfile

numpy.core.records.fromfile(fd, dtype=None, shape=None, offset=0, formats=None, names=None, titles=None, aligned=False, byteorder=None)[source]

根据二进制文件数据创建数组参数 :fd :str 或 file type

如果file是字符串或类似路径的对象,

则将打开该文件,否则假定它是文件对象。

文件对象必须支持随机访问

(即,它必须具有tell 和 seek方法)。

dtype :data-type, 可选

所有数组的有效dtype

shape :int 或 int的tuple,可选

offset :int, 可选

在文件中开始读取的位置。

formats, names, titles, aligned, byteorder:

如果dtype为None,

则将这些参数传递给numpy.format_parser以构造dtype。

请参阅该功能以获取详细文档

返回值 :np.recarray

由包含在文件中的数据组成的记录数组。

例子>>> from tempfile import TemporaryFile

>>> a = np.empty(10,dtype='f8,i4,a5')

>>> a[5] = (0.5,10,'abcde')

>>>

>>> fd=TemporaryFile()

>>> a = a.newbyteorder('

>>> a.tofile(fd)

>>>

>>> _ = fd.seek(0)

>>> r=np.core.records.fromfile(fd, formats='f8,i4,a5', shape=10,

... byteorder='

>>> print(r[5])

(0.5, 10, 'abcde')

>>> r.shape

(10,)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值