Getting all unique values in a vector-valued vertex property map
This might be a stupid question, but I have a graph with a vector<str>-valued vertex property map. That is, each vertex has a vector containing one or more strings encoding some metadata about the vertex. I want to get a single 1d-list/array containing all the unique string values encoded in this property map, over all vertices in the graph. What's the best way to do that? I know that I'll have to use the get_2d_array() method on the property map, but I can't really understand what the documentation means when it says: "The parameter pos must be a sequence of integers which specifies the *indexes of the property values which will be used.*" -- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
Hi, I agree that the documentation in this case is not easy to understand. I had a similar situation and get_2d_array([0]) worked. Best, Alex On Fri, Feb 10, 2017 at 11:26 AM, gogurt <gogurt@gmail.com> wrote:
This might be a stupid question, but I have a graph with a vector<str>-valued vertex property map. That is, each vertex has a vector containing one or more strings encoding some metadata about the vertex.
I want to get a single 1d-list/array containing all the unique string values encoded in this property map, over all vertices in the graph. What's the best way to do that?
I know that I'll have to use the get_2d_array() method on the property map, but I can't really understand what the documentation means when it says: "The parameter pos must be a sequence of integers which specifies the *indexes of the property values which will be used.*"
-- View this message in context: http://main-discussion-list- for-the-graph-tool-project.982480.n3.nabble.com/Getting- all-unique-values-in-a-vector-valued-vertex-property-map-tp4027016.html Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com. _______________________________________________ graph-tool mailing list graph-tool@skewed.de https://lists.skewed.de/mailman/listinfo/graph-tool
Ahhh. OK. I see now. Thanks so much Tiago. -- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
On 10.02.2017 16:26, gogurt wrote:
This might be a stupid question, but I have a graph with a vector<str>-valued vertex property map. That is, each vertex has a vector containing one or more strings encoding some metadata about the vertex.
I want to get a single 1d-list/array containing all the unique string values encoded in this property map, over all vertices in the graph. What's the best way to do that?
The simplest way is usually the best way. The question above is not really specific to graph-tool, if you think about it: vals = set() for v in g.vertices(): for x in prop[v]: vals.add(x)
I know that I'll have to use the get_2d_array() method on the property map, but I can't really understand what the documentation means when it says: "The parameter pos must be a sequence of integers which specifies the *indexes of the property values which will be used.*"
This does not give what you want at all. This function is about getting a two-dimensional array representation of vector-value property maps. The property map values can have different lengths, and hence to construct a 2D array the function requires the positions of the individual vectors that will be used to construct the matrix. Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
participants (3)
-
Alexandre Bovet -
gogurt -
Tiago de Paula Peixoto