看板 Python 關於我們 聯絡資訊
先稍微整理一下 ※ 引述《MAGICXX (逢甲阿法)》之銘言: : 大家好 : 1. : 我現在有一組程式碼有問題 : upperb=NDVI_LST[col[0]]>0.0 : lowerb=NDVI_LST[col[0]]<0.1 : edge_1=NDVI_LST[(upperb & lowerb)] col_0 = col[0] col_1 = col[1] upperb=NDVI_LST[col_0]>0.0 lowerb=NDVI_LST[col_0]<0.1 edge_1=NDVI_LST[(upperb & lowerb)] : lst_values=[] : for i in edge_1[col[0]]: : LST=NDVI_LST.loc[NDVI_LST[col[0]]==i,col[1]] : NDVI=i # 這行不知道在幹嘛 : for j in LST.values: : lst_values.append(j) : df.loc[0.0,'w1月']=max(lst_values) # 這段看不懂在幹嘛 max_lst_values = edge_1[col_1].max() min_lst_values = edge_1[col_1].min() : lst_values=[] : for i in edge_1[col[0]]: : LST=NDVI_LST.loc[NDVI_LST[col[0]]==i,col[1]] : NDVI=i : for j in LST.values: : lst_values.append(j) : df.loc[0.0,'d1月']=min(lst_values) : 因為我現在會需要有12個月的重複計算以及 : upperb以及lowerb的重複計算(0.0 ,0.1, 0.2, 0.3.....1.0) : 原本我是用下面的code跑 可是每次都會剩下最後一個值然後把前面的值蓋掉 : NDVI_bound=np.around(np.linspace(0,1,11).tolist(),decimals=2) : for k in range(1,13): : for j in range(23): : for i in range(10): : upperb=NDVI_LST[col[int(j)]]>NDVI_bound[int(i)] : lowerb=NDVI_LST[col[int(j)]]<NDVI_bound[int(i)+1] : edge_1=NDVI_LST[(upperb & lowerb)] : lst_values=[] : for l in edge_1[col[int(j)]]: : LST=NDVI_LST.loc[NDVI_LST[col[int(j)]]==l,col[int(j)+1]] : NDVI=i : for m in LST.values: : lst_values.append(m) : if lst_values==[]: : df.loc[NDVI_bound[int(i)+1],'w'+str(k)+'月']=0 : df.loc[NDVI_bound[int(i)+1],'d'+str(k)+'月']=0 : else: : df.loc[NDVI_bound[int(i)+1],'w'+str(k)+'月']=max(lst_values) : df.loc[NDVI_bound[int(i)+1],'d'+str(k)+'月']=min(lst_values) : 我想問一下大家 這樣要怎麼縮減這個程式碼才會是對的? : 不然我光是用一個一個貼 就要2000多行程式碼 可是明明是重複做一樣的動作... 這邊完全沒有對K做操作 請檢查一下code跟邏輯 : 2.查表 : 我找的值是從上面那張表出來的 : D1 W1 : 0.1 23.7 22.4 : 0.2 25.8 26.88 : 0.3 29.8 30.64 : . : . : . : 1.0 35.26 38.31 : 我現在給他一個值 他要怎麼找到在這張表的哪個範圍? : 比如說 我現在給他27.33這個數值 他要怎麼找到是在0.2~0.3之間 : 然後跟我說上限是29.8 下限是25.8 這樣? : 有兩個問題 再麻煩各位了QQ binary search -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.249.7.252 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1618879263.A.4F5.html
MAGICXX: 那個K是月份 在最後面那邊有用到K喔 04/20 10:09
TuCH: 只有在存的時候用到 那不是每次都一樣嗎 04/20 16:48