# Identifying connected networks among array elements

Solution for Identifying connected networks among array elements
is Given Below:

Consider numpy array `a`, formed as follows:

a) Each row holds unique digits 0 to 7
b) In any row, column `j` (0 based) cannot hold value `j`

``````a = np.array([[5, 2, 1, 7, 6, 0, 4, 3]
[6, 7, 4, 5, 2, 3, 0, 1]
[5, 2, 1, 4, 3, 0, 7, 6]])
``````

Thinking of 0 to 7 as vertices of an octagon, we want to identify connected networks in each pair of rows.

For rows 0 and 1 of array a, we will identify edges in the octagon at BELOW, LEFT using the following method:

column 0 holds a 5 and a 6, so 05 and 06 are edges in the network
column 1 holds a 2 and a 7, so 12 and 17 are edges in the network
…etc…
column 7 holds a 3 and a 1, so 73 and 71 are edges in the network

So, it is clear that rows 0 and 1 of array `a` form 1 connected network. (LEFT diagram)

Using the same method, we see that rows 0 and 2 of array `a` form 3 connected networks. (CENTER diagram)
Using the same method, we see that rows 1 and 2 of array `a` form 2 connected networks. (RIGHT diagram)

QUESTION: For each combination of rows in array `a`, I need to identify a single element from each network. (any network element will do, but I chose the smallest in each network)

The desired output could look like this:
[1st row, 2nd row, any network element]:

``````b = np.array([0, 1, 0]
[0, 2, 0]
[0, 2, 1]
[0, 2, 3]
[1, 2, 0]
[1, 2, 3]])
``````