GIVEN: a numpy array, a
, where each successive pair of elements shares an element with some other pair in the row.
Spaces have been added to emphasize the paired nature of the elements.
import numpy as np
a = np.array([[1,2, 1,3, 1,4, 6,1],
[2,3, 2,4, 4,5, 8,5],
[6,7, 1,2, 1,5, 2,6],
[7,8, 2,3, 8,9, 3,4]])
The details of the shared elements will be important:
a[0]
every pair shares an element (ie: 1) with every other pair
a[1]
1st pair shares with 2nd, 2nd with 3rd, 3rd with 4th
a[2]
1st pair shares with 4th, 2nd with 3rd and 4th
a[3]
1st pair shares with 3rd, 2nd with 4th
PROBLEM: I want to eliminate rows like a[3]
whose PAIRS do NOT FORM a SINGLE CONNECTED NETWORK.
The 1st and 3rd pairs of a[3]
, for example, have no way to 'get' to the 2nd or 4th pairs. The pairs in a[3]
form two distinct disconnected networks, so a[3]
should be eliminated.
The pairs in a[0]
, a[1]
, and a[2]
, by contrast, form a single connected network, so these rows are kept. (we can 'get' from any pair to any other pair)
I don't really have a good idea about how to approach this problem.