Skip to content
Advertisement

Fastest way to find a 2d array inside another array that holds multiple 2d arrays

Hi I’m trying to perform a search operation in an array that contains multiple 2d arrays comparing it’s itens to a specific array. I managed to do it using a for loop iterating trough the itens inside the big array but I have to perform this search 10^6 times and the length of this for loop can grow up to 2^100 so it is becoming very time consuming. I’m wondering if there is a way to make this search faster using a np.where or np.isin() function.

this is an example of the slower working method

JavaScript

and I would like to make something like this. I need to store the indexes where b is found inside a in the index c of the dictionary frequencies

JavaScript

Advertisement

Answer

You can use NumPy.all with a two-axis then use NumPy.argwhere for finding the index like below:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement