您可以用formatting of string玩,直到你的愿望的结果,并根据需要5%的线,许多方式可以做到这一点,你可以使用gruper recipe从itertools,做这样的事情:
from itertools import zip_longest
def grouper(iterable, n, fillvalue=None):
"Collect data into fixed-length chunks or blocks"
# grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
args = [iter(iterable)] * n
return zip_longest(*args, fillvalue=fillvalue)
def my_print(data,size=5):
for group in grouper(data,size):
print(" ".join("{: .8e}".format(x) for x in group if x is not None))
在此我拿5个元素的组时
和组中变换每个数字的欲望格式"{: .8e}".format(x)
,然后加入一起
测试
>>> test=[0.749381113, 1.87971394e-14, 0.819110455, -2.75795136e-16, -1.12488769e-16, 0.164873995, -0.0745597632, -2.34514676e-15, -3.14121102e-17, 0.0696946913, 0.0, 0.00002541]
>>> my_print(test)
7.49381113e-01 1.87971394e-14 8.19110455e-01 -2.75795136e-16 -1.12488769e-16
1.64873995e-01 -7.45597632e-02 -2.34514676e-15 -3.14121102e-17 6.96946913e-02
0.00000000e+00 2.54100000e-05
>>>
你想通过线来打印一气呵成整个阵列,或者只是行? – Reti43