Skip to main content

Module numpy

Module numpy 

Source
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::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.
FieldDef
One field of a structured type.
Header
What a .npy header 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§

Dtype
An element type, as descr gives it.
Literal
A Python literal, as far as a .npy header uses them.
Open
What opening a NumPy file finds.

Constants§

MAGIC
The first six bytes of every .npy file.
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.
MAX_HEADER
The longest header read. NumPy’s own reader refuses past 10,000 bytes unless told otherwise; a structured type of many fields can be longer, and this is still small.

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; None when they are not a .npy file’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 .npy file.
members
The arrays of the archive at path, in the archive’s order.
open
Open path: a .npy file, or an archive’s array wanted names, or its one array.
open_file
The array of the .npy file at path.
open_in
The array whose .npy bytes start at bytes into bytes (the whole of a file, or a member stored in an archive) and run for len bytes, its one column named name.
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 most [MAX_DEPTH] deep.
plan
The columns of an array of header, named name where it is one column.
schema_preview
The columns an array would open with, from its header: a .npy file, or an archive’s member. None for 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.