﻿ Python NumPy: Get the values and indices of the elements that are bigger than 10 in a given array - w3resource

# Python NumPy: Get the values and indices of the elements that are bigger than 10 in a given array

## Python NumPy: Array Object Exercise-31 with Solution

Write a Python program to get the values and indices of the elements that are bigger than 10 in a given array.

Sample Solution:-

Python Code:

``````import numpy as np
x = np.array([[0, 10, 20], [20, 30, 40]])
print("Original array: ")
print(x)
print("Values bigger than 10 =", x[x>10])
print("Their indices are ", np.nonzero(x > 10))
```
```

Sample Output:

```Original array:
[[ 0 10 20]
[20 30 40]]
Values bigger than 10 = [20 20 30 40]
Their indices are  (array([0, 1, 1, 1]), array([2, 0, 1, 2]))
```

Python Code Editor:

```import numpy as np
x = np.array([[0, 10, 20], [20, 30, 40]])
print("Original array: ")
print(x)
print("Values bigger than 10 =", x[x>10])
print("Their indices are ", np.nonzero(x > 10))```

Improve this sample solution and post your code through Disqus