fromfile(file, dtype=float, count=-1, sep='', offset=0, *, like=None)
A highly efficient way of reading binary data with a known data-type, as well as parsing simply formatted text files. Data written using the tofile
method can be read using this function.
Do not rely on the combination of tofile
and fromfile
for data storage, as the binary files generated are not platform independent. In particular, no byte-order or data-type information is saved. Data can be stored in the platform independent .npy
format using save
and load
instead.
Open file object or filename.
:None:None:`pathlib.Path`
objects are now accepted.
Data type of the returned array. For binary files, it is used to determine the size and byte-order of the items in the file. Most builtin numeric types are supported and extension types may be supported.
Complex dtypes.
Number of items to read. -1
means all items (i.e., the complete file).
Separator between items if file is a text file. Empty ("") separator means the file should be treated as binary. Spaces (" ") in the separator match zero or more whitespace characters. A separator consisting only of spaces must match at least one whitespace.
The offset (in bytes) from the file's current position. Defaults to 0. Only permitted for binary files.
Reference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as like
supports the __array_function__
protocol, the result will be defined by it. In this case, it ensures the creation of an array object compatible with that passed in via this argument.
Construct an array from data in a text or binary file.
loadtxt
More flexible way of loading data from a text file.
Construct an ndarray:
>>> dt = np.dtype([('time', [('min', np.int64), ('sec', np.int64)]),
... ('temp', float)])
... x = np.zeros((1,), dtype=dt)
... x['time']['min'] = 10; x['temp'] = 98.25
... x array([((10, 0), 98.25)], dtype=[('time', [('min', '<i8'), ('sec', '<i8')]), ('temp', '<f8')])
Save the raw data to disk:
>>> import tempfile
... fname = tempfile.mkstemp()[1]
... x.tofile(fname)
Read the raw data from disk:
>>> np.fromfile(fname, dtype=dt) array([((10, 0), 98.25)], dtype=[('time', [('min', '<i8'), ('sec', '<i8')]), ('temp', '<f8')])
The recommended way to store and load data:
>>> np.save(fname, x)See :
... np.load(fname + '.npy') array([((10, 0), 98.25)], dtype=[('time', [('min', '<i8'), ('sec', '<i8')]), ('temp', '<f8')])
The following pages refer to to this document either explicitly or contain code examples using this.
numpy.fromfile
numpy.fromstring
numpy.rec.array
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them