﻿ NumPy: Search the index of a given array in another given array - w3resource # NumPy: Search the index of a given array in another given array

## NumPy: Array Object Exercise-171 with Solution

Write a NumPy program to search the index of a given array in another given array.

Sample Solution:

Python Code:

``````import numpy as np
np_array = np.array([[1,2,3], [4,5,6] , [7,8,9], [10, 11, 12]])
test_array = np.array([4,5,6])
print("Original Numpy array:")
print(np_array)
print("Searched array:")
print(test_array)
print("Index of the searched array in the original array:")
print(np.where((np_array == test_array).all(1)))
```
```

Sample Output:

```Original Numpy array:
[[ 1  2  3]
[ 4  5  6]
[ 7  8  9]
[10 11 12]]
Searched array:
[4 5 6]
Index of the searched array in the original array:

```

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