This is a pre-release version (2.5.0.dev0+git20251130.2de293a). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / rec / fromfile

function

numpy.rec:fromfile

source: build-install/usr/lib/python3.14/site-packages/numpy/_core/records.py :836

Signature

def   fromfile ( fd dtype = None shape = None offset = 0 formats = None names = None titles = None aligned = False byteorder = None )

Summary

Create an array from binary file data

Parameters

fd : str 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).

dtype : data-type, optional

valid dtype for all arrays

shape : int or tuple of ints, optional

shape of each array.

offset : int, 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

from tempfile import TemporaryFile
a = np.empty(10,dtype='f8,i4,a5')
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,a5', shape=10,
byteorder='<')
print(r[5])
r.shape

Aliases

  • numpy.rec.fromfile