Roma Karageorgievich - 1 year ago 67

Python Question

I have two numpy lists:

`x = ['A', 'A', 'C', 'A', 'V', 'A', 'B', 'A', 'A', 'A']`

`y = ['1', '2', '1', '1', '3', '2', '1', '1', '1', '1']`

How can I find indexes when simulataneously

`x`

`'A'`

`y`

`'2'`

I expect to get indexes [1, 5].

I tried to use:

`np.where(x == 'A' and y == '2')`

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You need to convert the list to numpy array in order to use vectorized operation such as `==`

and `&`

:

```
import numpy as np
np.where((np.array(x) == "A") & (np.array(y) == "2"))
# (array([1, 5]),)
```

Shorter version (if you are sure that x and y are numpy arrays):

```
>>> np.where(np.logical_and(x == 'A', y == '2'))
(array([1, 5]),)
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**