# code from https://github.com/divideconcept/fastnumpyio/blob/main/fastnumpyio.py import sys import numpy as np import numpy.lib.format import struct def save(file, array): magic_string=b"\x93NUMPY\x01\x00v\x00" header=bytes(("{'descr': '"+array.dtype.descr[0][1]+"', 'fortran_order': False, 'shape': "+str(array.shape)+", }").ljust(127-len(magic_string))+"\n",'utf-8') if type(file) == str: file=open(file,"wb") file.write(magic_string) file.write(header) file.write(array.data) def pack(array): size=len(array.shape) return bytes(array.dtype.byteorder.replace('=','<' if sys.byteorder == 'little' else '>')+array.dtype.kind,'utf-8')+array.dtype.itemsize.to_bytes(1,byteorder='little')+struct.pack(f'