Numpy where() in Python
# Introduction to Numpy Where in Python
Numpy is a fundamental library for scientific computing in Python. It provides high-performance multi-dimensional array objects and functions for manipulating these arrays. Numpy Where is an in-built function that is used to return the indices of elements in an input array where the given condition is satisfied. The Where function returns a tuple of arrays, one for each dimension of the array, containing the indices of the elements that satisfy the condition. The condition can be a boolean array, or a single boolean condition.
The Numpy Where function can be used to create boolean arrays and filter the elements of an array based on conditions. It can also be used to modify elements in an array based on conditions. In addition, the Where function can be used to select elements from one array based on conditions in another array. This makes it a powerful and versatile tool for data analysis. In this article, we will discuss the Numpy Where function and its various applications. We will also look at some examples of the Where function in action.
Worried About Failing Tech Interviews?
Attend our webinar on
"How to nail your next tech interview" and learn
.png)
Hosted By
Ryan Valles
Founder, Interview Kickstart

Our tried & tested strategy for cracking interviews

How FAANG hiring process works

The 4 areas you must prepare for

How you can accelerate your learnings
Register for Webinar
Numpy's `where()` function is a useful tool for returning the indices of elements in an array that satisfy a given condition. It is similar to a `for` loop, but instead of looping over the elements and performing a comparison, it returns the indices that satisfy the comparison.
Syntax:
```
np.where(condition)
```
Example:
```python
import numpy as np
arr = np.array([10, 20, 30, 40, 50])
result = np.where(arr > 25)
print(result)
```
Output:
`(array([2, 3, 4]),)`