graph_tool.VertexPropertyMap#

class graph_tool.VertexPropertyMap(pmap, g)[source]#

Bases: PropertyMap

This class provides a mapping from vertices to arbitrary properties.

See Property maps and PropertyMap for 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), where N is the number of vertices or edges, and M is the size of each property vector, with contains a copy of all entries of the vector-valued property map.

get_array()

Get a numpy.ndarray subclass (PropertyArray) with the property values.

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.

python_value_type()

Return the python-compatible value type of the map.

reserve(size)

Reserve enough space for size elements in underlying container.

resize(size)

Resize the underlying container to contain exactly size elements.

set_2d_array(a[, pos])

Set the entries of the vector-valued property map from a two-dimensional array a of shape (M,N), where N is the number of vertices or edges, and M is the size of each property vector.

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.

Attributes

a

Shortcut to the get_array() method as an attribute.

fa

The same as the a attribute, but instead an indexed array is returned, which contains only entries for vertices/edges which are not filtered out.

ma

The same as the a attribute, but instead a numpy.ma.MaskedArray object 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_type is specified, the value type is converted to the chosen type. 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).

data_ptr()#

Return the pointer to memory where the data resides.

get_2d_array(pos)#

Return a two-dimensional array of shape (M,N), where N is the number of vertices or edges, and M is the size of each property vector, with contains a copy of all entries of the vector-valued property map. The parameter pos must be a sequence of integers which specifies the indices of the property values which will be copied.

get_array()#

Get a numpy.ndarray subclass (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, None is returned instead. For vector and string objects, indirect array access is provided via the get_2d_array() and set_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 size elements in underlying container. If the original size is already equal or larger, nothing will happen.

resize(size)#

Resize the underlying container to contain exactly size elements.

set_2d_array(a, pos=None)#

Set the entries of the vector-valued property map from a two-dimensional array a of shape (M,N), where N is the number of vertices or edges, and M is the size of each property vector. If given, the parameter pos must be a sequence of integers which specifies the indices of the property values which will be set (i.e. rows if the a matrix).

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 a attribute, 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 the a attribute.

Note that because advanced indexing is triggered, a copy of the array is returned, not a view, as for the a attribute. Nevertheless, the assignment of values to the whole array at once works as expected.

ma#

The same as the a attribute, but instead a numpy.ma.MaskedArray object is returned, which contains only entries for vertices/edges which are not filtered out. If there are no filters in place, a regular PropertyArray is returned, which is identical to the a attribute.