How to filter a numpy array based on two or more conditions?
Creating a new array from the existing array whereas taking out some elements from that existing array and then creating a new one is called as filtering. In case of filtering the elements whose value at an index is "True" that are going to be ontained in the filtered array otherwise if the values at an index is "False" then it will be excluded from that filtered array.
import numpy as np
Sample_array = np.array([55,60,65,70,75,80,85,90])
filter_array =  ##take empty list for values in Sample_array: if values > 65: filter_array.append(True) ##append values which are greater than 65 else: filter_array.append(False) ##exclude values which are less than 65 new_filtered_array = Sample_array[filter_array] ## Apply it on the Sample array that we have taken
print("The filtered array is:", new_filtered_array)
The filtered array is: [70 75 80 85 90]
Here we can see the array has been filtered, as we have pass a condition where if the values are than "65" append that values and exclude the values which are less than "65".