Write a NumPy program to search the index of a given array in another given array.
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]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer