# P12.5 NumPy Boolean Indexing: Conditions ने Arrays Filter करा

Source: https://ravindrabagale.com/mr/datascience/py12-numpy-tutorial-for-beginners-arrays-math-and-filtering/p12-5-numpy-boolean-indexing-filter-arrays-with.html
Language: mr (Marathi with English technical terms)

हे का शिकायचं?

उशिरा झालेल्या deliveries किंवा मोठ्या orders च हव्या असतात.

हे काय आहे?

arr > 30 ने True/False mask मिळतो. arr[mask] फक्त True वाल्या values देतो. दोन conditions साठी & आणि | कंसासह वापरा. np.where(condition, a, b) values बदलतो.

कसं करायचं?

Step 1. Condition ने mask बनवा.
Step 2. arr[mask] ने filter करा.
Step 3. गरज असेल तर np.where.

उदाहरण A: Mask बनवा

```python
import numpy as np
amounts = np.array([450, 1200, 300, 2500, 800])
mask = amounts > 1000
print(mask)
```

Output:

```text
[False  True False  True False]
```

याचा अर्थ: प्रत्येक value साठी True/False मिळालं.

उदाहरण B: Filter करा आणि मोजा

```python
import numpy as np
amounts = np.array([450, 1200, 300, 2500, 800])
big = amounts[amounts > 1000]
print(big)
print((amounts > 1000).sum())
```

Output:

```text
[1200 2500]
2
```

याचा अर्थ: arr[mask] ने values मिळाल्या आणि mask.sum() ने count.

उदाहरण C: दोन conditions

```python
import numpy as np
amounts = np.array([450, 1200, 300, 2500, 800])
mid = amounts[(amounts >= 400) & (amounts <= 1000)]
print(mid)
```

Output:

```text
[450 800]
```

याचा अर्थ: & वापरताना प्रत्येक condition कंसात हवी.

उदाहरण D: np.where ने values बदला

```python
import numpy as np
amounts = np.array([450, 1200, 300, 2500, 800])
labels = np.where(amounts > 1000, "High", "Normal")
print(labels)
```

Output:

```text
['Normal' 'High' 'Normal' 'High' 'Normal']
```

याचा अर्थ: Condition नुसार प्रत्येक value ला label मिळालं.

रवींद्र बागले यांची tip

Brackets लक्षात ठेवा: `(a > 1) & (a < 5)`. त्याशिवाय Python चुकीच्या क्रमाने वाचतो आणि error देतो.
