(matrix)
| 61 | updated_data.to_csv(file_path, index=False) |
| 62 | |
| 63 | def format_matrix_str(matrix): |
| 64 | def format_float(num, total_width=20, decimal_places=12): |
| 65 | # strip all right 0s, then strip '.' |
| 66 | s = f"{num:{total_width}.{decimal_places}f}".rstrip("0").rstrip(".") |
| 67 | # add space to the left |
| 68 | return f"{s:>{total_width}}" |
| 69 | formatted = [ |
| 70 | [ |
| 71 | # f"{num:20.12f}".rstrip("0").rstrip(".") if "." in f"{num}" else f"{num:20}" |
| 72 | # f"{num:20.12f}" if "." in f"{num}" else f"{num:20}" |
| 73 | format_float(num, total_width=15, decimal_places=8) |
| 74 | for num in row |
| 75 | ] |
| 76 | for row in matrix |
| 77 | ] |
| 78 | rows = [ |
| 79 | f" [{', '.join(num for num in row)}]" |
| 80 | for row in formatted |
| 81 | ] |
| 82 | return " [\n" + ",\n".join(rows) + "\n ]" |
| 83 | |
| 84 | def save_list_of_matrices(matrices_tosave: List[List[List[float]]], save_path: str) -> None: |
| 85 | json_str = "[\n" + ",\n".join(format_matrix_str(mat) for mat in matrices_tosave) + "\n]" |
no test coverage detected