Return string representation of this matrix.
(self)
| 25 | self.array = [[default_value for _ in range(column)] for _ in range(row)] |
| 26 | |
| 27 | def __str__(self) -> str: |
| 28 | """ |
| 29 | <method Matrix.__str__> |
| 30 | Return string representation of this matrix. |
| 31 | """ |
| 32 | |
| 33 | # Prefix |
| 34 | s = f"Matrix consist of {self.row} rows and {self.column} columns\n" |
| 35 | |
| 36 | # Make string identifier |
| 37 | max_element_length = 0 |
| 38 | for row_vector in self.array: |
| 39 | for obj in row_vector: |
| 40 | max_element_length = max(max_element_length, len(str(obj))) |
| 41 | string_format_identifier = f"%{max_element_length}s" |
| 42 | |
| 43 | # Make string and return |
| 44 | def single_line(row_vector: list[float]) -> str: |
| 45 | nonlocal string_format_identifier |
| 46 | line = "[" |
| 47 | line += ", ".join(string_format_identifier % (obj,) for obj in row_vector) |
| 48 | line += "]" |
| 49 | return line |
| 50 | |
| 51 | s += "\n".join(single_line(row_vector) for row_vector in self.array) |
| 52 | return s |
| 53 | |
| 54 | def __repr__(self) -> str: |
| 55 | return str(self) |
nothing calls this directly
no outgoing calls
no test coverage detected