user785099 - 10 months ago 63

Python Question

There exists an

`nd.array`

`label1`

`[[0 0 0 ..., 0 0 0]`

[0 0 0 ..., 0 88 0]

[0 0 0 ..., 0 0 0]

...,

[0 0 1 ..., 0 0 0]

[0 0 0 ..., 0 2 0]

[0 0 0 ..., 0 0 0]]

Its shape is

`(729,816)`

`print(np.where(label1==label1.max()))`

`(array([ 0, 0, 0, ..., 234, 234, 234]), array([450, 451, 452, ..., 433, 434, 435]))`

Answer

- To get the sorted unique values in your array, do
`numpy.unique(label1)`

. - When called on a two-dimensional array,
`numpy.where`

returns two arrays which are the row and column coordinates of all matching entries. So, if`numpy.where`

returns`(array([0]), array([1]))`

it means that one match was found at row 0, column 1.

**EDIT:** If you want to extract and print the row and column coordinates from `numpy.where`

, you can do it like this:

```
rows, cols = np.where(label1==label1.max())
for row, col in zip(rows, cols):
print row, col
```

Source (Stackoverflow)