为了账号安全,请及时绑定邮箱和手机立即绑定

应用空间过滤

应用空间过滤

浮云间 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 关注
  • 74 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信