Question: I have the following arrays:

```
example_array = [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]
indexes = [[1,2,3], [2,3], [0,4,2], [1,4,3], [0,4,3], [1,2,3], [1,2]]

```

I would like to replace the elements in the example\_array with 1 according to the index in indexes. So, the expected result should be this:

```
example_array = [[0,1,1,1,0],[0,0,1,1,0],[1,0,1,0,1],[0,1,0,1,1],[1,0,0,1,1],[0,1,1,1,0],[0,1,1,0,0]].

```

I tried different approaches, for example to use pandas, like this:

```
matrix = pd.DataFrame(example_array)

for row in matrix:
    for i in indexes:
        for j in i:
            x_u.iloc[x, j] = 1

```

but it doesn't give me the hoped results! The solution does not need to use pandas library.
Thanks for the help!

Answer: 
You can just do this:

```
example_array = [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]]
indexes = [[1,2,3], [2,3], [0,4,2], [1,4,3], [0,4,3], [1,2,3], [1,2]]

for i,index in enumerate(indexes):
  for idx in index:
    example_array[i][idx] = 1
print example_array

```

Output: 

```
[[0, 1, 1, 1, 0], [0, 0, 1, 1, 0], [1, 0, 1, 0, 1], [0, 1, 0, 1, 1], [1, 0, 0, 1, 1], [0, 1, 1, 1, 0], [0, 1, 1, 0, 0]]

```
Using numpy array you can directly set specified indices to a desired value.

```
import numpy as np
example_array = np.array([[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0]])
indexes = [[1,2,3], [2,3], [0,4,2], [1,4,3], [0,4,3], [1,2,3], [1,2]]

for i, ind in enumerate(indexes):
    example_array[i, ind] = 1
print(a)

```

**Output**

```
[[0 1 1 1 0]
 [0 0 1 1 0]
 [1 0 1 0 1]
 [0 1 0 1 1]
 [1 0 0 1 1]
 [0 1 1 1 0]
 [0 1 1 0 0]]

```