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

Function load_array_from_bin

utils/io.py:77–99  ·  view source on GitHub ↗

Load a 1D NumPy array from a binary file. Args: filename (str): The name of the file to read the array from. Returns: np.ndarray: The loaded 1D array.

(filename)

Source from the content-addressed store, hash-verified

75 print("Error: Cannot write to file.")
76
77def load_array_from_bin(filename):
78 """
79 Load a 1D NumPy array from a binary file.
80
81 Args:
82 filename (str): The name of the file to read the array from.
83
84 Returns:
85 np.ndarray: The loaded 1D array.
86 """
87 try:
88 with open(filename, "rb") as file:
89 # Read the length of the array
90 length = int.from_bytes(file.read(4), byteorder='little')
91
92 # Read the array data
93 array = np.fromfile(file, dtype=np.double, count=length)
94
95 print(f"Array loaded from {filename}. Length: {length}")
96 return array
97 except IOError:
98 print("Error: Cannot read file.")
99 return None
100
101

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected