Question: I have a 2D NumPy array that of shape (1500, 3712). I want to find the indices of the array that have values between -10 and -40. So far I have:

```py
for item in lon_array:
    for value in item:
        if value >= -40 and value <= -10:
            find_index = np.where(lon_array == value)
            index = np.asarray(find_index).T

```

Since it is a really big array, is there any way to make this faster?

Answer: 
If `lon_array` is a list of lists (built-in basic data type of Python), using `enumerate(...)`would be the best approach to know the indices of an element:

```
for y, row in enumerate(lon_array):
    for x, value in enumerate(row):
        if -40 <= value <= -10:
            index = (y, x)
            # do something useful with it...

```
For completeness, you could use [`numpy.indices`](https://numpy.org/doc/stable/reference/generated/numpy.nonzero.html) as an alternative to the `numpy.where` based solution that was proposed in other answers:

```py
In [1245]: lon_array = np.linspace(-70, 20, 10).reshape(2, 5)

In [1246]: lon_array
Out[1246]: 
array([[-70., -60., -50., -40., -30.],
       [-20., -10.,   0.,  10.,  20.]])

In [1247]: idx = np.nonzero(np.logical_and(lon_array >= -40, lon_array <= -10))

In [1248]: idx
Out[1248]: (array([0, 0, 1, 1], dtype=int64), array([3, 4, 0, 1], dtype=int64))

In [1249]: lon_array[idx]
Out[1249]: array([-40., -30., -20., -10.])

```

The demo above shows that NumPy's `nonzero` returns a tuple of 1D arrays which triggers [advanced indexing](https://numpy.org/doc/stable/reference/arrays.indexing.html#advanced-indexing) when used as a selection object.