Creating graph vertices from numpy array <p>I have a numpy array full of values that I would like to create vertices from for every point in the array. I am using networkx as my graphing support method(documentation here: <a href="http://networkx.github.io/documentation/latest/tutorial/" rel="nofollow">http://networkx.github.io/documentation/latest/tutorial/</a> )</p> <p>I would like to treat each element within the array as a pixel location and create a vertex instance at each location. This is easy using a simple for loop:</p> <pre><code>new=np.arange(16) gnew=nx.Graph() for x in new: if new[x]&gt;0: gnew.add_node(x) h=gnew.number_of_nodes() print h </code></pre> <p>And as expected, 15 nodes will be printed. However, this becomes more tricky when you have identical values. For example:</p> <pre><code>new=np.ones(16) gnew=nx.Graph() for x in new: if new[x]&gt;0: gnew.add_node(x) h=gnew.number_of_nodes() print h </code></pre> <p>Now, because all values are identical-(1), only one node will be added to the graph. Is there a way to circumnavigate this?</p>