萌新求问关于print的问题
萌新求问:能否使用print把二维列表变成矩阵形式打印出来?
例:
原来的样子:matrix = [, , ]
打印后的样子:
matrix = [,
,
] 本帖最后由 jackz007 于 2021-10-20 11:45 编辑
matrix = [, , ]
print('matrix = [' , end = '')
for k in range(len(matrix)):
if k:
print(' ' * 9 , sep = '' , end = '')
print(matrix , sep = '' , end = '')
if k < len(matrix) - 1:
print(',')
else:
print(']') matrix = [, , ]
") if n == len(matrix)-1 else print(m) for n, m in enumerate(matrix)][
]
import numpy as np
matrix = np.array(matrix)
print(matrix)[
]
页:
[1]