亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

應用空間過濾

應用空間過濾

浮云間 2022-11-18 16:50:47
我有一個包含 6 列的文件,我必須繪制 2 個第一列,但要考慮在第 6 列中具有價值的點。第 6 列有很多零和幾乎為零的數字,當我放置a[5]>=0時,它也需要一些幾乎為零的點,另一方面,不可能進行浮點過濾,我的意思是在 float 數組上應用過濾器。如何應用列表過濾列以提取緩沖區并繪制 X 和 Y。import numpy as npimport matplotlib.pyplot as pltimport statistics from statistics import mode %matplotlib qtdef most_frequent(List):     counter = 0    num = List[0]     for i in List:         curr_frequency = List.count(i)         if(curr_frequency> counter):             counter = curr_frequency             num = i     return numwith open('file_1001.out', 'r') as f:    lines = f.readlines()    near = [float(line.split()[5]) for line in lines]    #list(filter(lambda  near: near = 0, lines))    x = [float(line.split()[0]) for line in lines]    y = [float(line.split()[1]) for line in lines]print(most_frequent(near))plt.plot(x[near<=0.0], y[near<=0.0], lw=1.75,label='Points filtered by 6th column= 0')plt.plot(x,y,label='Plot without filter')plt.axis('equal')plt.show()
查看完整描述

1 回答

?
大話西游666

TA貢獻1817條經驗 獲得超14個贊

你可以利用np.where. 這是一個可能有幫助的例子。


#cast your list as a numpy array   

a=np.asarray([0.1,0.01,0.02,0.0003,0.05,0.0009,0.0005],dtype=np.float32)

要獲得滿足您所需范圍的指數:

np.where((a<0.001) & (a>0.0003))[0]

要獲取與這些索引對應的值:

a[np.where((a<0.001) & (a>0.0003))]


查看完整回答
反對 回復 2022-11-18
  • 1 回答
  • 0 關注
  • 120 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號