How to Create a Filter Array That Will Return Only Designated Values in NumPy


In this example we will show how to create a filter array that will return only designated values in Python NumPy.

Source Code

import numpy as np

n = np.array([5, 6, 7, 8, 9, 10, 11, 12])

filter_boolean = n < 9

filter_n = n[filter_boolean]

print(filter_boolean)
print(filter_n)

Output:

[ True  True  True  True False False False False]
[5 6 7 8]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments