fpath=r”C:\Python\WR75\Y Cut\Xpol.txt”
“””
#csv是逗點分隔檔
內容如下:
100.000,10000,11000,12000
-30.000,-70.765,-77.594,-76.722
-29.500,-71.492,-78.381,-76.414
“””
raw_list=[]
with open(fpath, ‘r’) as f:
while True:
aline=f.readline()
print(aline)
if aline == “”: break
raw = aline.strip().split(“,”)
#raw是1D list
raw = [eval(i) for i in raw]
#總是需要印出來,才發現忘記eval()
raw_list.append(raw)
#raw_list是一個2D list
print(“raw:”,raw)
print(“raw_list”,raw_list)
print(type(raw_list))

fpath=r”C:\Python\WR75\Y Cut\Xpol.txt”
raw_list=[]
with open(fpath, ‘r’) as f:
while True:
aline=f.readline()
print(aline)
if aline == “”: break
raw = aline.strip().split(“,”)
raw = [eval(i) for i in raw]
#總是需要印出來,才發現忘記eval()
raw_list.append(raw)
print(“raw:”,raw)
print(“raw_list”,raw_list)
print(type(raw_list))
magind=100
angind=10000
MagIdx = raw_list[0].index(magind)
Idx = raw_list[0].index(angind)
print(MagIdx)
print(Idx)

raw_list[0]
[100.0, 10000, 11000, 12000]
因為檔案是縮小版
沒有0
原始檔案:
100~10000~15000~0~10000~15000
100, 0底下的資料都是角度,非強度
magind=100
angind=10000
MagIdx = raw_list[0].index(magind)
#100這個元素,index=0
Idx = raw_list[0].index(angind)
#10000這個元素,index=1
raw_list[0]
[100.0, 10000, 11000, 12000]


![Python提取2D array的一部份資料; import numpy; a[1: , 2:] ; a[1:-1 , 2:-1] Python提取2D array的一部份資料; import numpy; a[1: , 2:] ; a[1:-1 , 2:-1]](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2022/09/20220906122441_97.png?quality=90&zoom=2&ssl=1&resize=350%2C233)




![Python TQC考題604 眾數, cnt[L.index(n)]+=1, L[cnt.index(max(cnt))], if L.count(n)>maxcnt: Python TQC考題604 眾數, cnt[L.index(n)]+=1, L[cnt.index(max(cnt))], if L.count(n)>maxcnt:](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2022/04/20220430181911_73.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


近期留言