graph_tool.VertexPropertyMap#
- class graph_tool.VertexPropertyMap(pmap, g)[source]#
Bases:
PropertyMapThis class provides a mapping from vertices to arbitrary properties.
See Property maps and
PropertyMapfor more details.Methods
coerce_type([full])Return a copy of the property map with the most appropriate type, i.e. the simplest type necessary to accomodate all the values exactly.
copy([value_type, full])Return a copy of the property map.
data_ptr()Return the pointer to memory where the data resides.
get_2d_array(pos)Return a two-dimensional array of shape
(M,N), whereNis the number of vertices or edges, andMis the size of each property vector, with contains a copy of all entries of the vector-valued property map.Get a
numpy.ndarraysubclass (PropertyArray) with the property values.Get the graph class to which the map refers.
Return True if the property is writable.
key_type()Return the key type of the map.
Return the python-compatible value type of the map.
reserve(size)Reserve enough space for
sizeelements in underlying container.resize(size)Resize the underlying container to contain exactly
sizeelements.set_2d_array(a[, pos])Set the entries of the vector-valued property map from a two-dimensional array
aof shape(M,N), whereNis the number of vertices or edges, andMis the size of each property vector.set_value(val)Sets all values in the property map to
val.Shrink size of underlying container to accommodate only the necessary amount, and thus potentially freeing memory.
swap(other)Swap internal storage with
other.Return the value type of the map.
Attributes
Shortcut to the
get_array()method as an attribute.The same as the
aattribute, but instead an indexed array is returned, which contains only entries for vertices/edges which are not filtered out.The same as the
aattribute, but instead anumpy.ma.MaskedArrayobject is returned, which contains only entries for vertices/edges which are not filtered out.- coerce_type(full=True)#
Return a copy of the property map with the most appropriate type, i.e. the simplest type necessary to accomodate all the values exactly. If
full == False, in the case of filtered graphs only the unmasked values are copied (with the remaining ones taking the type-dependent default value).
- copy(value_type=None, full=True)#
Return a copy of the property map. If
value_typeis specified, the value type is converted to the chosen type. Iffull == False, in the case of filtered graphs only the unmasked values are copied (with the remaining ones taking the type-dependent default value).
- data_ptr()#
Return the pointer to memory where the data resides.
- get_2d_array(pos)#
Return a two-dimensional array of shape
(M,N), whereNis the number of vertices or edges, andMis the size of each property vector, with contains a copy of all entries of the vector-valued property map. The parameterposmust be a sequence of integers which specifies the indices of the property values which will be copied.
- get_array()#
Get a
numpy.ndarraysubclass (PropertyArray) with the property values.Note
An array is returned only if the value type of the property map is a scalar. For vector, string or object types,
Noneis returned instead. For vector and string objects, indirect array access is provided via theget_2d_array()andset_2d_array()member functions.Warning
The returned array does not own the data, which belongs to the property map. Therefore, if the graph changes, the array may become invalid. Do not store the array if the graph is to be modified; store a copy instead.
- get_graph()#
Get the graph class to which the map refers.
- is_writable()#
Return True if the property is writable.
- key_type()#
Return the key type of the map. Either ‘g’, ‘v’ or ‘e’.
- python_value_type()#
Return the python-compatible value type of the map.
- reserve(size)#
Reserve enough space for
sizeelements in underlying container. If the original size is already equal or larger, nothing will happen.
- resize(size)#
Resize the underlying container to contain exactly
sizeelements.
- set_2d_array(a, pos=None)#
Set the entries of the vector-valued property map from a two-dimensional array
aof shape(M,N), whereNis the number of vertices or edges, andMis the size of each property vector. If given, the parameterposmust be a sequence of integers which specifies the indices of the property values which will be set (i.e. rows if theamatrix).
- set_value(val)#
Sets all values in the property map to
val.
- shrink_to_fit()#
Shrink size of underlying container to accommodate only the necessary amount, and thus potentially freeing memory.
- swap(other)#
Swap internal storage with
other.
- value_type()#
Return the value type of the map.
- a#
Shortcut to the
get_array()method as an attribute. This makes assignments more convenient, e.g.:>>> g = gt.Graph() >>> g.add_vertex(10) <...> >>> prop = g.new_vertex_property("double") >>> prop.a = np.random.random(10) # Assignment from array
- fa#
The same as the
aattribute, but instead an indexed array is returned, which contains only entries for vertices/edges which are not filtered out. If there are no filters in place, the array is not indexed, and is identical to theaattribute.Note that because advanced indexing is triggered, a copy of the array is returned, not a view, as for the
aattribute. Nevertheless, the assignment of values to the whole array at once works as expected.
- ma#
The same as the
aattribute, but instead anumpy.ma.MaskedArrayobject is returned, which contains only entries for vertices/edges which are not filtered out. If there are no filters in place, a regularPropertyArrayis returned, which is identical to theaattribute.