Senin, 18 Maret 2019

python find connected components in a 3D graph / tuple with three elements?

I have a binary 3D numpy array, for which I would like to find connected components, i.d. neighbor elements with value 1.


data = np.random.binomial(1, 0.4, 1000)
data = data.reshape((10,10,10))

Alternatively I can get the coordinates for each element with value one and get a set of lists with three elements for which I could get neighboring clusters


coordinates = np.argwhere(data > 0)

connected_elements = []
for node in coordinates:
neighbors = #Get possible neighbors of node
if neighbors not in connected_elements:
connected_elements.append(node)
else:
connected_elements.index(neighbor).extend(node)

How can I do this, or implement a 2D connected_components function for a 3D setting?



from python find connected components in a 3D graph / tuple with three elements?

python find connected components in a 3D graph / tuple with three elements? Rating: 4.5 Diposkan Oleh: Admin

0 komentar:

Posting Komentar

Popular Posts