graph_tool.PropertyMap#

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

Bases: object

This base class provides a mapping from vertices, edges or whole graphs to arbitrary properties.

See Property maps for more details.

The possible property value types are listed below.

Type name

Alias

bool

uint8_t

int16_t

short

int32_t

int

int64_t

long, long long

double

float

long double

string

vector<bool>

vector<uint8_t>

vector<int16_t>

short

vector<int32_t>

vector<int>

vector<int64_t>

vector<long>, vector<long long>

vector<double>

vector<float>

vector<long double>

vector<string>

python::object

object

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)[source]#

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)[source]#

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()[source]#

Return the pointer to memory where the data resides.

get_2d_array(pos)[source]#

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()[source]#

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()[source]#

Get the graph class to which the map refers.

is_writable()[source]#

Return True if the property is writable.

key_type()[source]#

Return the key type of the map. Either ‘g’, ‘v’ or ‘e’.

python_value_type()[source]#

Return the python-compatible value type of the map.

reserve(size)[source]#

Reserve enough space for size elements in underlying container. If the original size is already equal or larger, nothing will happen.

resize(size)[source]#

Resize the underlying container to contain exactly size elements.

set_2d_array(a, pos=None)[source]#

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)[source]#

Sets all values in the property map to val.

shrink_to_fit()[source]#

Shrink size of underlying container to accommodate only the necessary amount, and thus potentially freeing memory.

swap(other)[source]#

Swap internal storage with other.

value_type()[source]#

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.