I have a nested list in python which contains some arrays. I want to check arrays with each other and then remove the rows that do not exist in next array. This is my nested list:
import numpy as np
all_points=[[[np.array([[1., 2.], [3., 4.], [7., 8.], [8., 9.]]), \
np.array([[20., 30.], [30., 20.], [10., 70.], [70., 40.]])],\
[np.array([[1., 2.], [3., 4.], [-0.8, -0.9], [7., 8.]]), \
np.array([[20., 30.], [30., 20.], [10., 70.], [70., 40.], [-70., -40.]])]]]
In my simplified example, it has only one main sublist. Main sublist again has two internal sublists. I want to check the first arrays of the first two internal sublists and only keep the common rows among them. If I check the first arrays of two internal sublists, I see that two rows are not common:
[[8., 9.], [-0.8, -0.9]]
So, I remove them. For the next array of internal sublists, only one row is not common in both of them: [-70., -40.]
which should be removed. Then, I want to export the list as the following:
cleaned_points=[[np.array([[1., 2.], [3., 4.], [7., 8.]]), \
np.array([[20., 30.], [30., 20.], [10., 70.], [70., 40.]])]]
After doing so, one sublist is removed because I concatenate all the arrays of each internal sublist. In reality I mave have more than one main sublist and two internal sublists. I want to repeat hat I did based on internal sublist in all the existing main sublists. I may have three sublists and then check for common rows between arrays of sublist 2 and 3. I do appreciate any help in advance.