How do I remove rows from a numpy array based on multiple conditions?

前端 未结 4 1078
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-10 16:34

I have a file with 4 columns and thousands of rows. I want to remove rows whose items in the first column are in a certain range. For example, if the data in my file is as f

4条回答
  •  Happy的楠姐
    2020-12-10 16:53

    You don't need to add complexity with numpy for this. I'm guessing you're reading your file in into a list of lists here (with each row being a list within the overall data list like this: ((18, 6.215, 0.025), (19, 6.203, 0.025), ...)). In which case use the below rule:

    for row in data:
        if((row[0] > 20 and row[0] < 25) or (row[0] > 30 and row[0] < 35)):
            data.remove(row)
    

提交回复
热议问题