import numpy as np
a = np.arange(120).reshape(2,3,4,5)
a:
舉例:如何在4D array中
取出17這個元素?
最上方的左邊跟
最下方的右邊都有4個[]
a[0 , : , : , :] #[]剩下3個
#專注看左邊有3~4個[]的地方,第0個元素有4個
a[0 , 0 , : , :] #[]剩下2個
#專注看左邊有2~3個[]的地方,第0個元素有3個
a[0,0,3] #[]剩下1個
a[0,0,3,2] #取出元素17
#電腦只認[],一層一層剝開
#4D array回到1D array
#只是元素皆為box (3D array)
print(a):
[[[[ 0 1 2 3 4]
[ 5 6 7 8 9]
[ 10 11 12 13 14]
[ 15 16 17 18 19]]
[[ 20 21 22 23 24]
[ 25 26 27 28 29]
[ 30 31 32 33 34]
[ 35 36 37 38 39]]
[[ 40 41 42 43 44]
[ 45 46 47 48 49]
[ 50 51 52 53 54]
[ 55 56 57 58 59]]]
[[[ 60 61 62 63 64]
[ 65 66 67 68 69]
[ 70 71 72 73 74]
[ 75 76 77 78 79]]
[[ 80 81 82 83 84]
[ 85 86 87 88 89]
[ 90 91 92 93 94]
[ 95 96 97 98 99]]
[[100 101 102 103 104]
[105 106 107 108 109]
[110 111 112 113 114]
[115 116 117 118 119]]]]
推薦hahow線上學習python: https://igrape.net/30afN
使用pandas讀進來的df_Raw:
(左半部為H/V Amp
右半部為H/V Phase)
[[[‘H’ ‘H’]
[‘H’ ‘H’]
[‘H’ ‘H’]]
[[‘H’ ‘H’]
[‘H’ ‘H’]
[‘H’ ‘H’]]
[[‘H’ ‘H’]
[‘H’ ‘H’]
[‘H’ ‘H’]]]
![Python: numpy 4d array如何取值? pandas如何去掉空列/空欄? 如何重置DataFrame的index/欄標籤? df_drop = df_Raw.dropna (axis=0, how="all").reset_index(drop=True) ; df_drop1.columns = list(range(df_drop1.columns.size)) - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/12/20221226115540_16.png)
![Python: numpy 4d array如何取值? pandas如何去掉空列/空欄? 如何重置DataFrame的index/欄標籤? df_drop = df_Raw.dropna (axis=0, how="all").reset_index(drop=True) ; df_drop1.columns = list(range(df_drop1.columns.size)) - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/12/20221226115553_61.png)
![Python: numpy 4d array如何取值? pandas如何去掉空列/空欄? 如何重置DataFrame的index/欄標籤? df_drop = df_Raw.dropna (axis=0, how="all").reset_index(drop=True) ; df_drop1.columns = list(range(df_drop1.columns.size)) - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/12/20221226115711_83.png)
![Python: numpy 4d array如何取值? pandas如何去掉空列/空欄? 如何重置DataFrame的index/欄標籤? df_drop = df_Raw.dropna (axis=0, how="all").reset_index(drop=True) ; df_drop1.columns = list(range(df_drop1.columns.size)) - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/12/20221226150408_88.png)
推薦hahow線上學習python: https://igrape.net/30afN
同邏輯處理右半部的H/V Phase:
3D的H Phase與V Phase:
#仿造前面的4D aryHVA,
#但axis 0長度增加到4
HVAP = np.vstack( (aryHA,aryVA,aryHP,aryVP) )
#同效果
aryHVAP[0,:,:,:] = aryHA #H Amp
aryHVAP[1,:,:,:] = aryVA #V Amp
aryHVAP[2,:,:,:] = aryHP #H Phase
aryHVAP[3,:,:,:] = aryVP #V Phase
或者做一個dict
四個key分別為
“aryHA” #H Amp
“aryVA” #V Amp
“aryHP” #H Phase
“aryVP” #V Phase
四個value皆為對應的3D array
也會好理解
使用4D array
就只能用0, 1, 2, 3代表
4D aryHVAP:
4D aryHVAP[2:,]跟df_Raw右半邊比較:
推薦hahow線上學習python: https://igrape.net/30afN
近期留言