Question: Can anyone tell me how to fix the following code? np.where should return index 0.

```
import numpy as np
listoftups=[("a", "b"), ("n"), ("c","d","e"), ("f", "g")]
np.where(listoftups==("a", "b"))

```

Answer: 
Assuming that you are trying to find the index of the tuple. Here is a solution which doesn't require numpy.

```
listoftups=[("a", "b"), ("n"), ("c","d","e"), ("f", "g")]
search_tuple = ("a", "b")
print(listoftups.index(search_tuple))

```

Will return 0

```
search_tuple = ("f", "g")
print(listoftups.index(search_tuple))

```

Will return 3
Here is how to force numpy to do what you want:

```
listoftups=[("a", "b"), ("n"), ("c","d","e"), ("f", "g")]

```

1. `where` operates on boolean arrays, a comparison like a==b will create a boolean array if a or b is a numpy array but not if both are native python objects. Let's also create an example with two occurrences of the search tuple.

.

```
arroftups = np.array(listoftups)
twice = np.concatenate(2*[listoftups])

```

2. one minor challenge is preventing numpy to attempt broadcasting when it sees the two element test tuple. We can do that by encapsulating it in a 0d array

.

```
probe = np.empty((),object)
probe[()] = "a", "b"

```

3. now we are good to go:

.

```
np.where(arroftups==probe)
# (array([0]),)
np.where(twice==probe)
# (array([0, 4]),)

```

Note if you are sure there is exactly one occurrence of the test tuple, then @Watchdog101's solution is probably better. But it will not work in the general case.