Expand description
NumPy arrays: .npy files, and .npz archives of them.
An .npy file is a short header, a Python dict literal giving the element type
(descr), the order (fortran_order) and the shape, and then the elements packed
end to end. Every element is the same size, so the data is read where it is, through
the strided decoder of the binary format specs (crate::formats::fixed_records): a map of
the file, decoded only where it is shown.
A structured element type gives a column per field (nested fields as outer.inner,
a subarray field as an Array column); a 1-D array is one column, named for the
array; a 2-D array is a grid with a column per index, 0 to n-1. More dimensions
are refused with the shape. Python objects (O), which only unpickling could read,
are refused and never unpickled.
An .npz archive is a zip of .npy files. Its arrays are listed on the home screen
like a directory’s files; an archive of one opens it. An array stored as it is in the
archive (np.savez) is read in place from a map of the archive; a compressed one
(np.savez_compressed) is decompressed once to a temporary file first.
Structs§
- Array
- An array read in place: its records and what to say about it.
- Field
Def - One field of a structured type.
- Header
- What a
.npyheader says. - Member
- One array of an archive.
- Plan
- The columns an array is read as, their starts counted from its first element, and its rows.
- Simple
- A type with no fields:
<f8,|S10,<M8[ns].
Enums§
Constants§
- MAGIC
- The first six bytes of every
.npyfile. - MAX_
COLUMNS - Columns one array may make, nested fields and repeated structs flattened.
- MAX_
GRID - A 2-D array of more columns than this is one Array column rather than a column per index.
Functions§
- detail
- What the Info panel’s NumPy tab says of an array.
- header_
len - Bytes before the header’s text, and the header’s length, from the file’s first 12
bytes;
Nonewhen they are not a.npyfile’s. - is_
archive - Whether a file is a NumPy archive: a zip file named
.npz. - looks_
like - Whether
head, the first bytes of a file, begins a.npyfile. - members
- The arrays of the archive at
path, in the archive’s order. - open_
file - The array of the
.npyfile atpath. - open_in
- The array whose
.npybytes startatbytes intobytes(the whole of a file, or a member stored in an archive) and run forlenbytes, its one column namedname. - parse_
dtype - Parse a
descr. - parse_
header - Parse the header at the start of
bytes, which must hold all of it. - parse_
literal - Parse the Python literal
text: strings, integers,True,False,None, lists, tuples and dicts, nested at mostMAX_DEPTHdeep. - plan
- The columns of an array of
header, namednamewhere it is one column. - schema_
preview - The columns an array would open with, from its header: a
.npyfile, or an archive’smember.Nonefor one that would not open. - shape_
text - The shape as Python writes it:
(3,),(2, 4),(). - tables
- The arrays of an archive as tables, with their columns, for the home screen.