1

I have a numpy array of folowing structure

sb = np.genfromtxt(open('HomePage/TodayList.txt', 'rb'),
                   delimiter=',', skiprows=0,
                   dtype=[('DataBase', np.str_, 16), ('Mode', np.str_, 16),
                          ('SMB', np.str_, 16),('Desc', np.str_, 128), 
                          ('Res', np.str_, 16), ('RightCnt', np.float64), 
                          ('PercentCnt', np.float64), ('ModelType', np.float64)])

The 6th column 'PercentCnt' which can be accessed by name 'PercentCnt' contains numbers from 0 to 50 the 7th column 'ModelType' contains numbers from 0 to 5 so i need to remove or delete array rows which match these criteria 'PercentCnt'<50 and 'ModelType'<2.

2 Answers 2

2

The condition

sb['PercentCnt'] >= 50

is the condition for keeping things on this column, and the condition

sb['ModelType'] >= 2

is the same for the other column.

You can combine these with np.logical_and:

keep = np.logical_and(sb['PercentCnt'] >= 50, sb['ModelType'] >= 2)

Finally, just keep the rows you wish to keep:

sb[keep]
Sign up to request clarification or add additional context in comments.

Comments

1

You can find all rows matching your criteria by use of a column-wise comparison for PercentCnt and ModelType and connection using np.logical_and. Doing that, you actually copy all other rows rather than to delete the ones you wanted to get rid of, but the effect is the same.

sb = sb[np.logical_and(sb["PercentCnt"]>=50, sb["ModelType"]>=2)]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.