[ Web Proxy ]
URL:
Viewing: https://numpy.org/doc/stable/reference/generated/../generated/numpy.rec.fromfile.html [Back]  [Original]

numpy.rec.fromfile — NumPy v2.5 Manual
Back to top
Search the docs ...:

numpy.rec.fromfile#

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

Create an array from binary file data

Parameters:
fdstr or file type

If file is a string or a path-like object then that file is opened, else it is assumed to be a file object. The file object must support random access (i.e. it must have tell and seek methods).

dtypedata-type, optional

valid dtype for all arrays

shapeint or tuple of ints, optional

shape of each array.

offsetint, optional

Position in the file to start reading from.

formats, names, titles, aligned, byteorder

If dtype is None, these arguments are passed to numpy.format_parser to construct a dtype. See that function for detailed documentation

Returns:
np.recarray

record array consisting of data enclosed in file.

Examples

Try it in your browser!
>>> from tempfile import TemporaryFile
>>> a = np.empty(10,dtype='f8,i4,S5')
>>> a[5] = (0.5,10,'abcde')
>>>
>>> fd=TemporaryFile()
>>> a = a.view(a.dtype.newbyteorder('<'))
>>> a.tofile(fd)
>>>
>>> _ = fd.seek(0)
>>> r=np.rec.fromfile(fd, formats='f8,i4,S5', shape=10,
... byteorder='<')
>>> print(r[5])
(0.5, 10, b'abcde')
>>> r.shape
(10,)

Web Proxy Viewer  |  New URL  |  Original Page