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’]]]




推薦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

![Python如何寫入docx文件? from docx import Document ; doc = Document() ; table = doc.add_table(rows=5, cols=3) ; table.cell(r,c).text = str(tabs[r][c]) ; doc.add_heading ; p = doc.add_paragraph ; p.add_run ; doc.add_picture ; 使用wordPad開啟會少最後一個row,可以用免費的LibreOffice Python如何寫入docx文件? from docx import Document ; doc = Document() ; table = doc.add_table(rows=5, cols=3) ; table.cell(r,c).text = str(tabs[r][c]) ; doc.add_heading ; p = doc.add_paragraph ; p.add_run ; doc.add_picture ; 使用wordPad開啟會少最後一個row,可以用免費的LibreOffice](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2022/09/20220914154313_30.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python 如何用pandas.Series.nsmallest() 找到n個與target差距最小的index?再從中找到距離idxmax最近的index?避免誤抓sidelobes的index? targetIdx = (serMean-target_value).abs().nsmallest(n).index.tolist() ;Series切片: .loc[標籤名1:標籤名2] (會含標籤名2) ; .iloc[位置1:位置2] (不含位置2) Python 如何用pandas.Series.nsmallest() 找到n個與target差距最小的index?再從中找到距離idxmax最近的index?避免誤抓sidelobes的index? targetIdx = (serMean-target_value).abs().nsmallest(n).index.tolist() ;Series切片: .loc[標籤名1:標籤名2] (會含標籤名2) ; .iloc[位置1:位置2] (不含位置2)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2023/02/20230222082954_53.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Excel TQC考題208: Competition,自訂格式: [<=50]0; 頁面配置>版面設定 展開>頁首/頁尾 Excel TQC考題208: Competition,自訂格式: [<=50]0; 頁面配置>版面設定 展開>頁首/頁尾](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2022/04/20220411102844_81.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python陣列介紹:List[ ], Tuple( ), Set{ }, Dictionary{ }, for迴圈 Python陣列介紹:List[ ], Tuple( ), Set{ }, Dictionary{ }, for迴圈](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2022/01/1643329597-856443d20256b1a850089a56d07657bf.png?quality=90&zoom=2&ssl=1&resize=350%2C233)




近期留言