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,)