Py学习  »  Python

python在一个包含三个元素的3D图形/元组中查找连接的组件?

hirschme • 5 年前 • 1770 次点击  

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

或者,我可以用值1得到每个元素的坐标,并用3个元素得到一组列表,这样我就可以得到相邻的集群

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)

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54031
 
1770 次点击  
文章 [ 3 ]  |  最新文章 5 年前