With numpy I am using the below algorithm to find the index of an element of a list in a separate list
IndexList = np.zeros(len(x))
for i in range(len(x)):
positionx = np.where(cx == x[i])
positiony = np.where(cy == y[i])
Index = np.intersect1d(positionx, positiony)
IndexList[i] = Index
This in itself is quite fast but I would like to know if there is a faster way to achieve the same purpose. Is there a better module to do this with than numpy
? or maybe some other numpy
functions that make this process faster? Can this kind of snippet be made faster with a pythonic approach or with comprehensions?
Ultimately I want to see whether the matrix that contains cx and cy have certain (x,y) coordinate pair that match the current x y pair from the two lists.
Example: cx, cy x, y are 1D numpy
arrays
cx cy x y
45 30 20 10
20 10 19 13
44 53
19 13
In this case indexList = [1, 3]