import numpy as np
data = bytes(np.array([1,2], dtype="<u2"))
datab'\x01\x00\x02\x00'
Without using standard tools (e.g. xarray’s or numpy’s file io functions), think of a way of storing a numpy array on the filesystem. Please store the array’s contents in some binary (i.e. non-text) format. You may choose between text or binary representation for metadata.
Push a branch containing the scripts which can perform the above mentioned tasks. Open a MR and add Tobias Kölling as reviewer until 2025-06-24.
To extract the underlying bytes from a numpy array, you can use bytes(), e.g.:
… and to get it back into numpy, use np.frombuffer():
Keep in mind, that when reading and writing bytes objects using Pythons file io, pass binary mode (b) to open:
When packing multiple variables into a fixed byte-layout, you might also want to check out Python’s struct library.