应用空间过滤

我有一个包含 6 列的文件,我必须绘制 2 个第一列,但要考虑在第 6 列中具有价值的点。第 6 列有很多零和几乎为零的数字,当我放置a[5]>=0时,它也需要一些几乎为零的点,另一方面,不可能进行浮点过滤,我的意思是在 float 数组上应用过滤器。如何应用列表过滤列以提取缓冲区并绘制 X 和 Y。



import numpy as np

import matplotlib.pyplot as plt

import statistics 

from statistics import mode 

%matplotlib qt


def 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 num



with 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()


浮云间
浏览 96回答 1
1回答

大话西游666

你可以利用np.where.&nbsp;这是一个可能有帮助的例子。#cast your list as a numpy array&nbsp; &nbsp;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))]
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python