-
numpy.core.records.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
If file is a string then that file is opened, else it is assumed to be a file object.
123456789101112131415>>>
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
,)
numpy.core.records.fromfile()

2025-01-10 15:47:30
Please login to continue.