# Python | Find elements within range in numpy

Given numpy array, the task is to find elements within some specific range. Let’s discuss some ways to do the task.

Method #1: Using `np.where()`

 `# python code to demonstrate ` `# finding elements in range ` `# in numpy array ` `import` `numpy as np ` ` `  `ini_array ``=` `np.array([``1``, ``2``, ``3``, ``45``, ``4``, ``7``, ``810``, ``9``, ``6``]) ` ` `  `# printing initial array ` `print``(``"initial_array : "``, ``str``(ini_array)); ` ` `  `# find elements in range 6 to 10 ` `result ``=` `np.where(np.logical_and(ini_array>``=` `6``, ini_array<``=` `10``)) ` ` `  `# printing result ` `print``(``"resultant_array : "``, result) `

Output:

```initial_array :  [  1   2   3  45   4   7 810   9   6]
resultant_array :  (array([5, 7, 8]),)
```

Method #2: Using `numpy.searchsorted()`

 `# Python code to demonstrate ` `# finding elements in range ` `# in numpy array ` ` `  `import` `numpy as np ` ` `  `ini_array ``=` `np.array([``1``, ``2``, ``3``, ``45``, ``4``, ``7``, ``9``, ``6``]) ` ` `  `# printing initial array ` `print``(``"initial_array : "``, ``str``(ini_array)); ` ` `  ` `  `# find elements in range 6 to 10 ` `start ``=` `np.searchsorted(ini_array, ``6``, ``'left'``) ` `end ``=` `np.searchsorted(ini_array, ``10``, ``'right'``) ` `result ``=` `np.arange(start, end) ` ` `  `# printing result ` `print``(``"resultant_array : "``, result) `

Output:

```initial_array :  [ 1  2  3 45  4  7  9  6]
resultant_array :  [5 6 7]
```

Method #3: Using *

 `# Python code to demonstrate ` `# finding elements in range ` `# in numpy array ` ` `  `import` `numpy as np ` ` `  `ini_array ``=` `np.array([``1``, ``2``, ``3``, ``45``, ``4``, ``7``, ``9``, ``6``]) ` ` `  `# printing initial array ` `print``(``"initial_array : "``, ``str``(ini_array)); ` ` `  ` `  `# find elements in range 6 to 10 ` `result ``=` `ini_array[(ini_array>``6``)``*``(ini_array<``10``)] ` ` `  `# printing result ` `print``(``"resultant_array : "``, result) `

Output:

```initial_array :  [ 1  2  3 45  4  7  9  6]
resultant_array :  [7 9]
```

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up Programming freaktech Enthusiast and have interest in learning new upcoming technologies

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.