我有字典形式的数据:
import numpy as np, Pysolar, datetime
my_data={'A': np.array([[-157.0, -158.0],[-29.0,30.0]]),
'B': np.array([[-160.0, -161.0],[-31.0,32.0]]),
'C': np.array([[-164.0, -165.0],[-33.0,34.0]])}
现在我已经得到了答案:
for x,y in my_data.iteritems():
lons, lats = y[0], y[1]
answers =[]
for e,f in zip(lons,lats):
answer = Pysolar.GetAltitude(e, f, datetime.datetime.utcnow())
answers.append(answer)
print answers #CORRECT ANSWER
但是,如何在字典表格中获取我的答案,为my_data中的相应组(A,B,C)分配答案?
答案 0 :(得分:1)
您可以使用新词典存储答案:
answers_dict = {}
for x, y in my_data.iteritems():
lons, lats = y[0], y[1]
answers = []
for e,f in zip(lons,lats):
answer = Pysolar.GetAltitude(e, f, datetime.datetime.utcnow())
answers.append(answer)
answers_dict[x] = answers