[英]Convert the values from dictionary to list format in Python
我運行了Python代碼,這是完整的代碼,如下所示:
import MDAnalysis as mda
import matplotlib.pyplot as plt
%matplotlib inline
u = mda.Universe('nptmd.tpr','nptmd.xtc')
H = u.select_atoms('byres(name OW HW1 HW2)')
A = u.select_atoms('byres(name OW HW1 HW2)')
D = u.select_atoms('byres(name OW HW1 HW2)')
hb_ac = hbonds.HydrogenBondAutoCorrel(u, acceptors=A, hydrogens=H, donors=D,bond_type='continuous',sample_time=5,nruns=20000,nsamples=10,pbc=True,angle_crit=130.0, dist_crit=3.0)
hb_ac.run()
hb_ac.solve()
time = hb_ac.solution['time']
results = hb_ac.solution['results']
tau = hb_ac.solution['tau']
fit=hb_ac.solution['fit']
estimate = hb_ac.solution['estimate']
print("{time} {results}".format(time=time,results=results))
print("{time} {estimate}".format(time=time,estimate=estimate))
plt.figure(1,figsize=(15, 5))
plt.figure(1,figsize=(15, 5))
plt.subplot(122)
plt.xlabel('time')
plt.ylabel('HBLc')
plt.title('HBL Continuos')
plt.plot(time,results, 'ro')
plt.plot(time,estimate)
plt.show()
print (tau)
我得到的結果是:-
[0. 0.5 1. 1.5 2. 2.5 3. 3.5 4.] [1.0000000e+00 5.2790266e-01 3.2588491e-01 2.1265593e-01 1.4223534e-01 9.6894175e-02 6.6584438e-02 4.6033673e-02 3.1977266e-02]
但我希望結果為:
0. 1.0000000e+00
0.5 5.2790266e-01
1. 3.2588491e-01
1.5 2.1265593e-01
2. 1.4223534e-01
2.5 9.6894175e-02
3. 6.6584438e-02
3.5 4.6033673e-02
4. 3.1977266e-02
我如何獲得上述輸出..?
任何建議都將受到高度贊賞。
這顯示了如何打印列表列表:
a = [ [1, 2, 3, 4], [11, 12, 13, 14]]
# as tuples
for row in zip(a[0], a[1]):
print row
# as formated output
for row in zip(a[0], a[1]):
print "{} {}".format(*row)
如果您想使用確切的數據結構,請發布一個最少的代碼,該代碼無需任何修改或外部數據即可運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.