Remove elements larger than a specific value Using Numpy
Python3
# Remove list elements greater than a given value using numpy import numpy as np num_list = [ 30 , 200 , 65 , 88 , 98 , 500 , 34 ] # convert list to numpy array arr = np.array(num_list) # remove numbers greater than 100 new_arr = arr[arr < = 100 ] # display the new_arr after removing the # values that are greater than 100 print (new_arr) #This code is contributed by Edula Vinay Kumar Reddy |
Output:
[30 65 88 98 34]
Time complexity: O(n)
Auxiliary Space: O(1)
Remove elements larger than a specific value from a list in Python
In this article, we will learn to remove elements from a list that is larger than a specific value in Python.
Example
Input: [12, 33, 10, 20, 25], value = 21
Output: [12, 10, 20]
Explanation: Removed all element from the list that are greater than 21.