# python-scipyHow can I use Python Numpy to select elements from an array based on multiple conditions?

To select elements from an array based on multiple conditions using Python Numpy, we can use the `np.where()`

function. This function takes a condition as an argument, and returns the indices of the elements in the array that satisfy the condition.

For example:

```
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
indices = np.where((arr > 2) & (arr < 8))
print(indices)
```

This will output `(array([0, 1, 1, 2], dtype=int64), array([1, 0, 1, 2], dtype=int64))`

The `np.where()`

function can take multiple conditions, which are evaluated using the bitwise operators `&`

(and) and `|`

(or).

The parts of the code are:

`np.where()`

: function used to select elements from an array based on multiple conditions`arr > 2`

: condition to select elements greater than 2`arr < 8`

: condition to select elements less than 8`&`

: bitwise operator to combine the two conditions

## Helpful links

### More of Python Scipy

- How do I create a 2D array of zeros using Python and NumPy?
- How do I create a zero matrix using Python and Numpy?
- How do I create a numpy array of zeros using Python?
- How can I use Python and SciPy to implement a quantum Monte Carlo simulation?
- How can I use Python and SciPy to find the zeros of a function?
- How to use Python, XML-RPC, and NumPy together?
- How can I use the x.shape function in Python Numpy?
- How do I use Python Numpy to read and write Excel (.xlsx) files?
- How can I use Python and SciPy to calculate a Hessenberg matrix?
- How do I create a numpy array of zeros using Python?

See more codes...