1 回答

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個(gè)贊
range()生成一個(gè)可用于此目的的可迭代對(duì)象,從 0 開始到您指定的任何值結(jié)束:
density = np.zeros((6, 91, 181))
days = range(5) # assign days to be an iterator, e.g. range()
for i,e in df.iterrows():
lat = int((e['Latitude']+90)/2)
long = int(e['Longitude']/2)
if lat == 0.0 and long == 0.0:
day = next(days) # assign day by popping the first value from that iterator
print(day)
density[day,lat,long] = e['rho']
如果您想要一個(gè)從零開始遞增的無限數(shù)字列表,您可以制作自己的無限數(shù)字生成器:
def inf_ints():
i = 0
while True:
yield i
i += 1
...
days = inf_ints()
...
添加回答
舉報(bào)