Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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))[0])

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:
[1]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now