MCPcopy Create free account
hub / github.com/ComputationalRobotics/XM-code / save_array_to_bin

Function save_array_to_bin

utils/io.py:56–75  ·  view source on GitHub ↗

Save a 1D NumPy array to a binary file. Args: filename (str): The name of the file to save the array. array (np.ndarray): The 1D array to save.

(filename, array)

Source from the content-addressed store, hash-verified

54 return None, None
55
56def save_array_to_bin(filename, array):
57 """
58 Save a 1D NumPy array to a binary file.
59
60 Args:
61 filename (str): The name of the file to save the array.
62 array (np.ndarray): The 1D array to save.
63 """
64 try:
65 with open(filename, "wb") as file:
66 # Write the length of the array as a 4-byte integer
67 length = array.size
68 file.write(length.to_bytes(4, byteorder='little'))
69
70 # Write the array data
71 array.tofile(file)
72
73 print(f"Array saved to {filename}. Length: {length}")
74 except IOError:
75 print("Error: Cannot write to file.")
76
77def load_array_from_bin(filename):
78 """

Callers

nothing calls this directly

Calls 1

writeMethod · 0.80

Tested by

no test coverage detected