Monday 8 March 2021

Most efficient way to find neighbors of neighbors in python

Let's consider, there are two arrays I and J which determines the neighbor pairs.

I = np.array([0, 0, 1, 2, 2, 3])
J = np.array([1, 2, 0, 0, 3, 2])

Which means element 0 has 2 neighbors 1, and 2. Element 1 has only 0 as neighbor and so on. What is the most efficient way to create arrays of all neighbor triples I', J', K' such that j is neighbor of i and k is neighbor of j given the condition i, j, and k are different elements (i != j != k)?

Ip = np.array([0, 0, 2, 3])
Jp = np.array([2, 2, 0, 2])
Kp = np.array([0, 3, 1, 0])

Of course, inefficient way is to loop over element in python. However, is there an efficient algorithm working on 10-500 million elements.



from Most efficient way to find neighbors of neighbors in python

No comments:

Post a Comment