Generating index numbers of inner branches in a symmetric network in Python

Question:

I have two symmetric networks. For every network, I am looking for a mathematical relation to generate index numbers of inner branches highlighted in green.

For 3x3 on the left, Index=[3,5,6,8].
For 4x4 on the right, Index=[4,5,7,8,9,11,12,14,15,16,18,19].

enter image description here

Asked By: Klimt865

||

Answers:

I found a solution to solve this problem but I think is not the smartest way however it works ! I have admitted the network is a square, tell me if I was wrong.

I calculate all boundaries one by one then I remove the set of boundaries in the set of branches of the network.

# size of a side of the network
N = 3

top = [i for i in range(N)]
left = [N + i * (2 * N + 1) for i in range(N)]
right = [2 * N + i * (2 * N + 1) for i in range(N)]
bottom = [i for i in range(right[-1] + 1, right[-1] + 1 + N)]

total = set(i for i in range(bottom[-1] + 1))

outer = {*top, *left, *right, *bottom}
result = total - outer
print(result)
Answered By: Julien Sorin
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.