Alejandro Sazo - 6 months ago 24

Python Question

I have a numpy array A with n rows of size 3. Each row is composed by three integers, each one is a integer which refers to another position inside the numpy array. For example If I want the rows refered by

`N[4]`

`N[N[4]]`

`N = np.array([[2, 3, 6], [12, 6, 9], [3, 10, 7], [8, 5, 6], [3, 1, 0] ... ])`

N[4] = [3, 1 ,0]

N[N[4]] = [[8, 5, 6]

[12, 6, 9]

[2, 3, 6]]

I am building a function that modifies N, and I need to modify N[N[x]] for some specified x which is a parameter too (4 in the example). I want to change all the 6 in the subarray for another number (let's say 0), so I use numpy.where to find the indexes, which are

`where_is_6 = np.where(N[N[4]] == 6)`

Now, if I replace directly like

`N[N[4]][where_is_6] = 0`

`var = N[N[4]]`

`var[where_is_6]`

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

Answer Source

Sounds like you just need to convert the indices to the original `N`

's coordinates:

```
row_idxs = N[4]
r,c = np.where(N[row_idxs] == 6)
N[row_idxs[r],c] = 0
```

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