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

## NumPy: Array Object Exercise-31 with Solution

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

Pictorial Presentation: 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:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

﻿

## Python: Tips of the Day

Set comprehension:

```>>> m = {x ** 2 for x in range(5)}
>>> m
{0, 1, 4, 9, 16}
```