Skip to main content
added 105 characters in body
Source Link
Statham
  • 4.1k
  • 2
  • 35
  • 46

Note: this is for python 2.7 version

You can use a lambda function to deal with the problem, and it works both on NumPy array and list.

your_list = [11, 22, 23, 44, 55]
result = filter(lambda x:your_list[x]>30, range(len(your_list)))
#result: [3, 4]

import numpy as np
your_numpy_array = np.array([11, 22, 23, 44, 55])
result = filter(lambda x:your_numpy_array [x]>30, range(len(your_list)))
#result: [3, 4]

And you can use

result[0]

to get the first index of the filtered elements.

For python 3.6, use

list(result)

instead of

result

You can use a lambda function to deal with the problem, and it works both on NumPy array and list.

your_list = [11, 22, 23, 44, 55]
result = filter(lambda x:your_list[x]>30, range(len(your_list)))
#result: [3, 4]

import numpy as np
your_numpy_array = np.array([11, 22, 23, 44, 55])
result = filter(lambda x:your_numpy_array [x]>30, range(len(your_list)))
#result: [3, 4]

And you can use

result[0]

to get the first index of the filtered elements.

Note: this is for python 2.7 version

You can use a lambda function to deal with the problem, and it works both on NumPy array and list.

your_list = [11, 22, 23, 44, 55]
result = filter(lambda x:your_list[x]>30, range(len(your_list)))
#result: [3, 4]

import numpy as np
your_numpy_array = np.array([11, 22, 23, 44, 55])
result = filter(lambda x:your_numpy_array [x]>30, range(len(your_list)))
#result: [3, 4]

And you can use

result[0]

to get the first index of the filtered elements.

For python 3.6, use

list(result)

instead of

result
Active reading. Added the import statement so that it works out of the box.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

You can use a lambda function to deal with the problem, and it works both on numpyNumPy array and list.

your_list = [11, 22, 23, 44, 55]
result = filter(lambda x:your_list[x]>30, range(len(your_list)))
#result: [3, 4] 

import numpy as np
your_numpy_array = np.array([11, 22, 23, 44, 55])
result = filter(lambda x:your_numpy_array [x]>30, range(len(your_list)))
#result: [3,4]   4]

And you can use

result[0]

to get the first index of the filtered elements.

You can use lambda function to deal with the problem, and it works both on numpy array and list.

your_list = [11,22,23,44,55]
result = filter(lambda x:your_list[x]>30,range(len(your_list)))
#result: [3,4]

your_numpy_array = np.array([11,22,23,44,55])
result = filter(lambda x:your_numpy_array [x]>30,range(len(your_list)))
#result: [3,4]   

And you can use

result[0]

to get the first index of the filtered elements.

You can use a lambda function to deal with the problem, and it works both on NumPy array and list.

your_list = [11, 22, 23, 44, 55]
result = filter(lambda x:your_list[x]>30, range(len(your_list)))
#result: [3, 4] 

import numpy as np
your_numpy_array = np.array([11, 22, 23, 44, 55])
result = filter(lambda x:your_numpy_array [x]>30, range(len(your_list)))
#result: [3, 4]

And you can use

result[0]

to get the first index of the filtered elements.

Source Link
Statham
  • 4.1k
  • 2
  • 35
  • 46

You can use lambda function to deal with the problem, and it works both on numpy array and list.

your_list = [11,22,23,44,55]
result = filter(lambda x:your_list[x]>30,range(len(your_list)))
#result: [3,4]

your_numpy_array = np.array([11,22,23,44,55])
result = filter(lambda x:your_numpy_array [x]>30,range(len(your_list)))
#result: [3,4]   

And you can use

result[0]

to get the first index of the filtered elements.