Skip to content
Advertisement

how do I match and find a vector in a Numpy array?

I have a Numpy array with size [2000,6].now I have an array with size [1,6] and I want to know which row of the main Numpy array is the same as this [1,6] array. if it exists in the main array, return the index of the row. for example row 1. but I do not want to use for loops because it is really time-consuming. I do not know how I can find a vector in an array and extract its related index. please help me with this issue. Thanks

Advertisement

Answer

Assuming you are using NumPy for this, your goal can be obtained by using the numpy.where method.

NumPy Solution

You can ignore this cell as I am just creating a simulated version of your problem:

JavaScript
JavaScript

Python List solution

JavaScript
JavaScript

Resources

numpy.wherehttps://numpy.org/doc/stable/reference/generated/numpy.where.html

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