【发布时间】:2018-08-28 21:00:17
【问题描述】:
我有什么:
import numpy as np
l = np.array([['a11','a12'],['a21','a22']])
layout = '{!s:6}'*2
for i in range(np.shape(l)[1]):
print(layout.format(*l[i]))
输出:
a11 a12
a21 a22
我想要什么:
def table (two_dim_array):
(i,j) = np.shape (two_dim_array)
layout = '{!s:6}'*j
#for k in range (i):
#return layout.format(*two_dim_array[k])
return 'a string that matches the table printed above'
我猜上面的代码是不言自明的。我想以函数的形式重写上述输出,该函数将输出与上述打印匹配的字符串。
【问题讨论】:
-
嗨,андрэ,我不太明白。这段代码目前做了什么,你希望它做什么?此外,“#output”之后的两行让我认为如果我尝试运行它就不会编译;这些应该是非代码块吗?
标签: python string python-3.x numpy