36 with open(file_path,
'r')
as file:
38 line = line.split(
';', 1)[0]
39 parts = line.strip().
split(
'=')
42 if name.strip() == variable_name:
43 print(f
"Found variable {variable_name} in the line: {line.strip()}")
45 vector_str = value.strip()
47 vector_str_with_commas =
','.join(vector_str.split())
48 vector = np.array([float(item)
for item
in vector_str_with_commas.split(
',')])
50 except ValueError
as e:
51 print(f
"Error converting to a NumPy array: {e}")
54 except FileNotFoundError:
67 with open(file_path,
'r')
as file:
68 found_variable =
False
71 clean_line = line.split(
';', 1)[0].strip()
75 parts = clean_line.split(
'=')
78 if name.strip() == variable_name:
79 print(f
"Found variable {variable_name} in the line: {line.strip()}")
81 matrix_lines.append(value.strip())
85 matrix_lines.append(line.split(
';')[0].strip())
88 matrix_lines.append(clean_line)
93 matrix_str =
' '.join(matrix_lines)
94 matrix_values = [item
for item
in matrix_str.split()
if is_number(item)]
95 matrix_values = [float(item)
for item
in matrix_values]
97 num_rows = len(matrix_lines)
99 num_cols = len(matrix_values) // num_rows
101 matrix = np.array(matrix_values).reshape((num_rows, num_cols))
103 except ValueError
as e:
104 print(f
"Error converting to a NumPy array: {e}")
107 except FileNotFoundError:
108 print(f
"File not found: {file_path}")