import numpy as np
x = np.random.random((3,3)) #point-set 1
y = np.random.random((3,3)) #point-set 2
neighbors_of_x = np.array([[0,1],[0],[0]])
#^^ contains indices of neighbors of points in x, in y.
#each point can have different number of neighbors in y.
#Below, for every point in x, subtract from its neighbor in y
for i in range(x.shape[0]):
print(x[i,:] - y[neighbors_of_x[i],:])
The above is representative example; The actual point-sets may have 1000s of points. Hence, I want to "vectorize" the last 2 lines (for loop)
Is there a way to do this without a for-loop in the end, with every index i
processed in parallel?
Note : Since neighbors_of_x
can have varying number of indices at each i
, that array is of dtype object
and hence I'm unable to directly use it to select elements of y