NumpyFile
Base class: Object
Represents a NumPy .npy or .npz file handle.
Use .npy files for a single direct array value and .npz files for named arrays.
Example
NumpyFile("values.npy", "w").write([1.0, 2.0, 3.0])
var values = NumpyFile("values.npy").read(as_real | as_list)
NumpyFile("archive.npz", "w").write("samples", [1, 2, 3])
Constructors
NumpyFile(const string path) -> NumpyFile
Prepares a NumPy file in read/write mode, creating it on first write if needed.
Parameters
- path: File path. Missing extensions default to .npy.
Example
var f = NumpyFile("values.npy")
NumpyFile(const string path, const string mode) -> NumpyFile
Prepares a NumPy file with an explicit mode.
Modes:
- "r": read-only, file must exist
- "r+": read/write, file must exist
- "w": read/write, create or truncate on first write
- "w-" or "x": create on first write, fail if it exists
- "a": read/write, create on first write if missing (default)
Parameters
- path: File path.
- mode: File open mode.
Example
var f = NumpyFile("archive.npz", "w")
Members
| Name | Description |
|---|---|
| dtype | Returns the dtype descriptor of a named .npz array. |
| exists | Checks whether a named array exists in a .npz archive. |
| is_npy | Returns whether this handle targets a .npy file. |
| is_npz | Returns whether this handle targets a .npz file. |
| list_datasets | Lists named arrays in a .npz archive. |
| path | Returns the resolved file path. |
| rank | Returns the rank of a named .npz array. |
| read | Reads a named complex sparse matrix from a .npz archive. |
| shape | Returns the shape of a .npy array. |
| size | Returns the element count of a .npy array. |
| write | Writes a sparse matrix densely to a .npy file and returns the file for chaining. |