# Table of Contents
- [Welcome to graph-tool’s documentation! — graph-tool 2.98 documentation](#welcome-to-graph-tool-s-documentation-graph-tool-2-98-documentation)
- [Cookbook guides — graph-tool 2.98 documentation](#cookbook-guides-graph-tool-2-98-documentation)
- [Parallel algorithms — graph-tool 2.98 documentation](#parallel-algorithms-graph-tool-2-98-documentation)
- [graph_tool — graph-tool 2.98 documentation](#graph-tool-graph-tool-2-98-documentation)
- [Submodules — graph-tool 2.98 documentation](#submodules-graph-tool-2-98-documentation)
- [Vertex — graph-tool 2.98 documentation](#vertex-graph-tool-2-98-documentation)
- [Edge — graph-tool 2.98 documentation](#edge-graph-tool-2-98-documentation)
- [VertexPropertyMap — graph-tool 2.98 documentation](#vertexpropertymap-graph-tool-2-98-documentation)
- [PropertyMap — graph-tool 2.98 documentation](#propertymap-graph-tool-2-98-documentation)
- [Quick start guide — graph-tool 2.98 documentation](#quick-start-guide-graph-tool-2-98-documentation)
- [Graph — graph-tool 2.98 documentation](#graph-graph-tool-2-98-documentation)
- [EdgePropertyMap — graph-tool 2.98 documentation](#edgepropertymap-graph-tool-2-98-documentation)
- [GraphView — graph-tool 2.98 documentation](#graphview-graph-tool-2-98-documentation)
- [GraphPropertyMap — graph-tool 2.98 documentation](#graphpropertymap-graph-tool-2-98-documentation)
- [PropertyArray — graph-tool 2.98 documentation](#propertyarray-graph-tool-2-98-documentation)
- [ungroup_vector_property — graph-tool 2.98 documentation](#ungroup-vector-property-graph-tool-2-98-documentation)
- [group_vector_property — graph-tool 2.98 documentation](#group-vector-property-graph-tool-2-98-documentation)
- [edge_endpoint_property — graph-tool 2.98 documentation](#edge-endpoint-property-graph-tool-2-98-documentation)
- [incident_edges_op — graph-tool 2.98 documentation](#incident-edges-op-graph-tool-2-98-documentation)
- [perfect_prop_hash — graph-tool 2.98 documentation](#perfect-prop-hash-graph-tool-2-98-documentation)
- [map_property_values — graph-tool 2.98 documentation](#map-property-values-graph-tool-2-98-documentation)
- [infect_vertex_property — graph-tool 2.98 documentation](#infect-vertex-property-graph-tool-2-98-documentation)
- [value_types — graph-tool 2.98 documentation](#value-types-graph-tool-2-98-documentation)
- [load_graph — graph-tool 2.98 documentation](#load-graph-graph-tool-2-98-documentation)
- [openmp_get_num_threads — graph-tool 2.98 documentation](#openmp-get-num-threads-graph-tool-2-98-documentation)
- [openmp_enabled — graph-tool 2.98 documentation](#openmp-enabled-graph-tool-2-98-documentation)
- [openmp_set_num_threads — graph-tool 2.98 documentation](#openmp-set-num-threads-graph-tool-2-98-documentation)
- [load_graph_from_csv — graph-tool 2.98 documentation](#load-graph-from-csv-graph-tool-2-98-documentation)
- [openmp_get_schedule — graph-tool 2.98 documentation](#openmp-get-schedule-graph-tool-2-98-documentation)
- [openmp_set_schedule — graph-tool 2.98 documentation](#openmp-set-schedule-graph-tool-2-98-documentation)
- [show_config — graph-tool 2.98 documentation](#show-config-graph-tool-2-98-documentation)
- [openmp_get_thresh — graph-tool 2.98 documentation](#openmp-get-thresh-graph-tool-2-98-documentation)
- [openmp_set_thresh — graph-tool 2.98 documentation](#openmp-set-thresh-graph-tool-2-98-documentation)
- [central_point_dominance — graph-tool 2.98 documentation](#central-point-dominance-graph-tool-2-98-documentation)
- [graph_tool.centrality — graph-tool 2.98 documentation](#graph-tool-centrality-graph-tool-2-98-documentation)
- [betweenness — graph-tool 2.98 documentation](#betweenness-graph-tool-2-98-documentation)
- [closeness — graph-tool 2.98 documentation](#closeness-graph-tool-2-98-documentation)
- [pagerank — graph-tool 2.98 documentation](#pagerank-graph-tool-2-98-documentation)
- [Unknown](#unknown)
- [Unknown](#unknown)
- [Unknown](#unknown)
- [Unknown](#unknown)
- [Unknown](#unknown)
- [Unknown](#unknown)
- [Unknown](#unknown)
- [Unknown](#unknown)
- [Unknown](#unknown)
- [Unknown](#unknown)
- [Unknown](#unknown)
- [Unknown](#unknown)
- [Unknown](#unknown)
---
# Welcome to graph-tool’s documentation! — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/index.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html#)
2.98 (stable)
[dev](https://graph-tool.skewed.de/static/docs/devindex.html)
[2.98 (stable)](https://graph-tool.skewed.de/static/docs/stableindex.html)
[2.97](https://graph-tool.skewed.de/static/docs/2.97index.html)
[2.96](https://graph-tool.skewed.de/static/docs/2.96index.html)
* [GitLab](https://git.skewed.de/count0/graph-tool)
* [Mastodon](https://social.skewed.de/@graph_tool)
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de)
* [Discourse](https://forum.skewed.de/c/graph-tool/5)
* [](https://graph-tool.skewed.de/)
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/index.md)
* [.md](https://graph-tool.skewed.de/static/docs/stable/_sources/index.md)
* .pdf
Light Dark System Settings
Welcome to graph-tool’s documentation!
======================================
Contents
--------
Welcome to graph-tool’s documentation
==================================================================================================================================================================
`graph-tool` is an efficient Python module for manipulation and statistical analysis of [graphs](https://en.wikipedia.org/wiki/Graph#Mathematics)
(a.k.a. [networks](https://en.wikipedia.org/wiki/Network_theory)
).
The [`graph_tool`](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#module-graph_tool "graph_tool")
module provides a [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
class and several algorithms that operate on it. The internals of this class, and of most algorithms, are written in C++ for performance, using [template metaprogramming](https://en.wikipedia.org/wiki/Template_metaprogramming)
for code specialization, and the [Boost Graph Library](http://www.boost.org/)
.
`graph-tool` can be [orders of magnitude faster](https://graph-tool.skewed.de/performance.html)
than Python-only alternatives, and therefore it is specially suited for large-scale network analysis.
Besides superior performance, `graph-tool` contains the following set of functionalities which are currently not available in most other comparable packages:
1. Comprehensive framework for [inferential community detection](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#inference-howto)
, build upon statistically principled approaches that avoid overfitting and are interpretable. (See [here](https://skewed.de/tiago/blog/modularity-harmful)
and \[[1](https://graph-tool.skewed.de/static/docs/stable/index.html#id13 "Tiago P. Peixoto. Descriptive vs. Inferential Community Detection in Networks: Pitfalls, Myths and Half-Truths. Elements in the Structure and Dynamics of Complex Networks, July 2023. arXiv:2112.00183, doi:10.1017/9781009118897, [sci-hub].")\
\] for why you should avoid off-the-shelf methods available in other software packages.)
2. Support for [OpenMP](https://en.wikipedia.org/wiki/OpenMP)
shared memory parallelism for several algorithms. See the [parallel algorithms](https://graph-tool.skewed.de/static/docs/stable/parallel.html#parallel-algorithms)
section fore more information.
3. High-quality [network visualization](https://graph-tool.skewed.de/static/docs/stable/draw.html#draw)
, both static and interactive, supporting [animations](https://graph-tool.skewed.de/static/docs/stable/demos/animation/animation.html#animation)
and [matplotlib integration](https://graph-tool.skewed.de/static/docs/stable/demos/matplotlib/matplotlib.html#matplotlib-sec)
.
4. [Filtered graphs](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-graph-filtering)
, i.e. graphs where nodes and edges are temporarily masked. These are first class citizens in the library, and are accepted by every function. Due to the use of C++ template metaprogramming, this functionality comes at no performance cost when filtering is not being used.
5. Efficient and fully documented [binary format](https://graph-tool.skewed.de/static/docs/stable/gt_format.html#sec-gt-format)
for network files.
6. Integration with the [Netzschleuder](https://networks.skewed.de/)
network data repository, enabling [`easy loading`](https://graph-tool.skewed.de/static/docs/stable/collection.html#graph_tool.collection.ns "graph_tool.collection.ns")
of network data.
7. Support for writing custom [C++ extensions](https://graph-tool.skewed.de/static/docs/stable/demos/cppextensions/cppextensions.html#cppextensions)
.
Installing graph-tool[#](https://graph-tool.skewed.de/static/docs/stable/index.html#installing-graph-tool "Link to this heading")
----------------------------------------------------------------------------------------------------------------------------------
Detailed installation instructions for various platforms are available [here](https://graph-tool.skewed.de/installation.html)
.
The easiest option is to use [conda](https://docs.conda.io/)
:
conda create \--name gt \-c conda-forge graph-tool
conda activate gt
Copy to clipboard
For HPC systems it is also straightforward to use [`graph_tool`](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#module-graph_tool "graph_tool")
with [Apptainer/Singularity](https://graph-tool.skewed.de/installation.html#installing-using-apptainer-n%C3%A9e-singularity)
.
Getting started[#](https://graph-tool.skewed.de/static/docs/stable/index.html#getting-started "Link to this heading")
----------------------------------------------------------------------------------------------------------------------
Yous should read first the [quick start guide](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#quickstart)
, followed by the various [cookbooks](https://graph-tool.skewed.de/static/docs/stable/demos/index.html#demos)
and explore all the examples in various [submodules](https://graph-tool.skewed.de/static/docs/stable/modules.html#submodules)
. For commonly asked questions, read the [FAQ](https://graph-tool.skewed.de/static/docs/stable/faq.html#sec-faq)
.
Asking questions and reporting bugs[#](https://graph-tool.skewed.de/static/docs/stable/index.html#asking-questions-and-reporting-bugs "Link to this heading")
--------------------------------------------------------------------------------------------------------------------------------------------------------------
If you have questions about using `graph-tool`, you are welcome to visit the [discussion forum](https://forum.skewed.de/c/graph-tool/5)
.
If you encounter a problem, open an issue in the [git repository](https://git.skewed.de/count0/graph-tool/-/issues)
.
Please don’t forget to check if your question has been asked before, or if a similar issue is open. When asking questions or reporting problems, it is important to include:
1. Your exact `graph-tool` version.
2. Your operating system.
3. A **minimal working example** that shows the problem.
Item **3** above is **very important**! If you provide us only the part of the code that you believe causes the problem, then it is not possible to understand the context that may have contributed to it.
How to use the documentation[#](https://graph-tool.skewed.de/static/docs/stable/index.html#how-to-use-the-documentation "Link to this heading")
------------------------------------------------------------------------------------------------------------------------------------------------
Documentation is available in two forms: docstrings provided with the code, and the full documentation available in [the graph-tool homepage](http://graph-tool.skewed.de/doc)
.
We recommend exploring the docstrings using [IPython](http://ipython.scipy.org/)
, an advanced Python shell with TAB-completion and introspection capabilities.
The docstring examples assume that `graph_tool.all` has been imported as `gt`:
\>>> import graph\_tool.all as gt
Copy to clipboard
Code snippets are indicated by three greater-than signs:
\>>> x \= x + 1
Copy to clipboard
Use the built-in `help` function to view a function’s docstring:
\>>> help(gt.Graph)
Copy to clipboard
Contents[#](https://graph-tool.skewed.de/static/docs/stable/index.html#contents "Link to this heading")
--------------------------------------------------------------------------------------------------------
* [Quick start guide](https://graph-tool.skewed.de/static/docs/stable/quickstart.html)
* [Creating graphs](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#creating-graphs)
* [Adding many edges and vertices at once](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#adding-many-edges-and-vertices-at-once)
* [Manipulating graphs](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#manipulating-graphs)
* [Iterating over vertices and edges](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#iterating-over-vertices-and-edges)
* [Example analysis: an online social network](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#example-analysis-an-online-social-network)
* [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#property-maps)
* [Transformations](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#transformations)
* [Internal property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#internal-property-maps)
* [Graph I/O](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#graph-i-o)
* [Graph filtering](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#graph-filtering)
* [Graph views](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#graph-views)
* [In-place graph filtering](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#in-place-graph-filtering)
* [Advanced iteration](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#advanced-iteration)
* [Faster iteration over vertices and edges without descriptors](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#faster-iteration-over-vertices-and-edges-without-descriptors)
* [Even faster, “loopless” iteration over vertices and edges using arrays](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#even-faster-loopless-iteration-over-vertices-and-edges-using-arrays)
* [Parallel algorithms](https://graph-tool.skewed.de/static/docs/stable/parallel.html)
* [The global interpreter lock (GIL)](https://graph-tool.skewed.de/static/docs/stable/parallel.html#the-global-interpreter-lock-gil)
* [Cookbook guides](https://graph-tool.skewed.de/static/docs/stable/demos/index.html)
* [Inferring modular network structure](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html)
* [Background: Nonparametric statistical inference](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#background-nonparametric-statistical-inference)
* [Minimum description length (MDL)](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#minimum-description-length-mdl)
* [The stochastic block model (SBM)](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#the-stochastic-block-model-sbm)
* [The nested stochastic block model](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#the-nested-stochastic-block-model)
* [Inferring the best partition](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#inferring-the-best-partition)
* [Hierarchical partitions](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#hierarchical-partitions)
* [Refinements using merge-split MCMC](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#refinements-using-merge-split-mcmc)
* [Model selection](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#model-selection)
* [Sampling from the posterior distribution](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#sampling-from-the-posterior-distribution)
* [Hierarchical partitions](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#id18)
* [Characterizing the posterior distribution](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#characterizing-the-posterior-distribution)
* [Model class selection](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#model-class-selection)
* [Edge weights and covariates](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#edge-weights-and-covariates)
* [Model selection](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#id27)
* [Posterior sampling](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#posterior-sampling)
* [Layered networks](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#layered-networks)
* [Assortative community structure](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#assortative-community-structure)
* [Ordered community structure](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#ordered-community-structure)
* [References](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#references)
* [Uncertain network reconstruction](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html)
* [Measured networks](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html#measured-networks)
* [Extraneous error estimates](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html#extraneous-error-estimates)
* [Latent Poisson multigraphs](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html#latent-poisson-multigraphs)
* [Latent triadic closures](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html#latent-triadic-closures)
* [Edge prediction as binary classification](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html#edge-prediction-as-binary-classification)
* [References](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html#references)
* [Network reconstruction from dynamics and behavior](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_indirect/reconstruction.html)
* [Reconstruction with synthetic data](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_indirect/reconstruction.html#reconstruction-with-synthetic-data)
* [Reconstruction with empirical data](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_indirect/reconstruction.html#reconstruction-with-empirical-data)
* [References](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_indirect/reconstruction.html#references)
* [Animations with graph-tool](https://graph-tool.skewed.de/static/docs/stable/demos/animation/animation.html)
* [Simple interactive animations](https://graph-tool.skewed.de/static/docs/stable/demos/animation/animation.html#simple-interactive-animations)
* [SIRS epidemics](https://graph-tool.skewed.de/static/docs/stable/demos/animation/animation.html#sirs-epidemics)
* [Dynamic layout](https://graph-tool.skewed.de/static/docs/stable/demos/animation/animation.html#dynamic-layout)
* [Interactive visualizations](https://graph-tool.skewed.de/static/docs/stable/demos/animation/animation.html#interactive-visualizations)
* [Integration with matplotlib](https://graph-tool.skewed.de/static/docs/stable/demos/matplotlib/matplotlib.html)
* [Integration with `basemap`](https://graph-tool.skewed.de/static/docs/stable/demos/matplotlib/matplotlib.html#integration-with-basemap)
* [Writing extensions in C++](https://graph-tool.skewed.de/static/docs/stable/demos/cppextensions/cppextensions.html)
* [Range-based iteration over vertices and edges](https://graph-tool.skewed.de/static/docs/stable/demos/cppextensions/cppextensions.html#range-based-iteration-over-vertices-and-edges)
* [Extracting specific property maps](https://graph-tool.skewed.de/static/docs/stable/demos/cppextensions/cppextensions.html#extracting-specific-property-maps)
* [Checked and unchecked property maps](https://graph-tool.skewed.de/static/docs/stable/demos/cppextensions/cppextensions.html#checked-and-unchecked-property-maps)
* [References](https://graph-tool.skewed.de/static/docs/stable/demos/cppextensions/cppextensions.html#references)
* [Submodules](https://graph-tool.skewed.de/static/docs/stable/modules.html)
* [`graph_tool`](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html)
* [Fundamental classes](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#fundamental-classes)
* [Property Maps](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#property-maps)
* [Graph IO](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#graph-io)
* [OpenMP configuration](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#openmp-configuration)
* [System information](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#system-information)
* [`graph_tool.centrality`](https://graph-tool.skewed.de/static/docs/stable/centrality.html)
* [Summary](https://graph-tool.skewed.de/static/docs/stable/centrality.html#summary)
* [`graph_tool.clustering`](https://graph-tool.skewed.de/static/docs/stable/clustering.html)
* [Summary](https://graph-tool.skewed.de/static/docs/stable/clustering.html#summary)
* [`graph_tool.collection`](https://graph-tool.skewed.de/static/docs/stable/collection.html)
* [Interface to the Netzschleuder online network repository](https://graph-tool.skewed.de/static/docs/stable/collection.html#interface-to-the-netzschleuder-online-network-repository)
* [Built-in collection of empirical network data](https://graph-tool.skewed.de/static/docs/stable/collection.html#built-in-collection-of-empirical-network-data)
* [Functions returning small graphs](https://graph-tool.skewed.de/static/docs/stable/collection.html#functions-returning-small-graphs)
* [Small graph atlas](https://graph-tool.skewed.de/static/docs/stable/collection.html#small-graph-atlas)
* [`graph_tool.correlations`](https://graph-tool.skewed.de/static/docs/stable/correlations.html)
* [Summary](https://graph-tool.skewed.de/static/docs/stable/correlations.html#summary)
* [`graph_tool.dynamics`](https://graph-tool.skewed.de/static/docs/stable/dynamics.html)
* [Discrete-time dynamics](https://graph-tool.skewed.de/static/docs/stable/dynamics.html#discrete-time-dynamics)
* [Continuous-time dynamics](https://graph-tool.skewed.de/static/docs/stable/dynamics.html#continuous-time-dynamics)
* [Belief propagation](https://graph-tool.skewed.de/static/docs/stable/dynamics.html#belief-propagation)
* [`graph_tool.draw`](https://graph-tool.skewed.de/static/docs/stable/draw.html)
* [Layout algorithms](https://graph-tool.skewed.de/static/docs/stable/draw.html#layout-algorithms)
* [Graph drawing](https://graph-tool.skewed.de/static/docs/stable/draw.html#graph-drawing)
* [`graph_tool.flow`](https://graph-tool.skewed.de/static/docs/stable/flow.html)
* [Summary](https://graph-tool.skewed.de/static/docs/stable/flow.html#summary)
* [Example network](https://graph-tool.skewed.de/static/docs/stable/flow.html#example-network)
* [`graph_tool.generation`](https://graph-tool.skewed.de/static/docs/stable/generation.html)
* [Random graph generation](https://graph-tool.skewed.de/static/docs/stable/generation.html#random-graph-generation)
* [Stochastic block models](https://graph-tool.skewed.de/static/docs/stable/generation.html#stochastic-block-models)
* [Geometric models](https://graph-tool.skewed.de/static/docs/stable/generation.html#geometric-models)
* [Graph transformations](https://graph-tool.skewed.de/static/docs/stable/generation.html#graph-transformations)
* [Graph set operations](https://graph-tool.skewed.de/static/docs/stable/generation.html#graph-set-operations)
* [Deterministic graphs](https://graph-tool.skewed.de/static/docs/stable/generation.html#deterministic-graphs)
* [`graph_tool.inference`](https://graph-tool.skewed.de/static/docs/stable/inference.html)
* [Nonparametric stochastic block model inference](https://graph-tool.skewed.de/static/docs/stable/inference.html#nonparametric-stochastic-block-model-inference)
* [Nonparametric network reconstruction](https://graph-tool.skewed.de/static/docs/stable/inference.html#nonparametric-network-reconstruction)
* [Semiparametric stochastic block model inference](https://graph-tool.skewed.de/static/docs/stable/inference.html#semiparametric-stochastic-block-model-inference)
* [Large-scale descriptors](https://graph-tool.skewed.de/static/docs/stable/inference.html#large-scale-descriptors)
* [`graph_tool.search`](https://graph-tool.skewed.de/static/docs/stable/search_module.html)
* [Summary](https://graph-tool.skewed.de/static/docs/stable/search_module.html#summary)
* [Example network](https://graph-tool.skewed.de/static/docs/stable/search_module.html#example-network)
* [`graph_tool.spectral`](https://graph-tool.skewed.de/static/docs/stable/spectral.html)
* [Sparse matrices](https://graph-tool.skewed.de/static/docs/stable/spectral.html#sparse-matrices)
* [Operator objects](https://graph-tool.skewed.de/static/docs/stable/spectral.html#operator-objects)
* [`graph_tool.stats`](https://graph-tool.skewed.de/static/docs/stable/stats.html)
* [Summary](https://graph-tool.skewed.de/static/docs/stable/stats.html#summary)
* [`graph_tool.topology`](https://graph-tool.skewed.de/static/docs/stable/topology.html)
* [Distance and paths](https://graph-tool.skewed.de/static/docs/stable/topology.html#distance-and-paths)
* [Graph comparison](https://graph-tool.skewed.de/static/docs/stable/topology.html#graph-comparison)
* [Matching and independent sets](https://graph-tool.skewed.de/static/docs/stable/topology.html#matching-and-independent-sets)
* [Spanning tree](https://graph-tool.skewed.de/static/docs/stable/topology.html#spanning-tree)
* [Sorting and closure](https://graph-tool.skewed.de/static/docs/stable/topology.html#sorting-and-closure)
* [Components and connectivity](https://graph-tool.skewed.de/static/docs/stable/topology.html#components-and-connectivity)
* [Graph classification](https://graph-tool.skewed.de/static/docs/stable/topology.html#graph-classification)
* [Directionality](https://graph-tool.skewed.de/static/docs/stable/topology.html#directionality)
* [Combinatorial optimizaton](https://graph-tool.skewed.de/static/docs/stable/topology.html#combinatorial-optimizaton)
* [`graph_tool.util`](https://graph-tool.skewed.de/static/docs/stable/util.html)
* [Summary](https://graph-tool.skewed.de/static/docs/stable/util.html#summary)
* [The `gt` file format](https://graph-tool.skewed.de/static/docs/stable/gt_format.html)
* [FAQ](https://graph-tool.skewed.de/static/docs/stable/faq.html)
* [How do I retrieve a vertex by its property map value?](https://graph-tool.skewed.de/static/docs/stable/faq.html#how-do-i-retrieve-a-vertex-by-its-property-map-value)
* [Is it possible to perform modularity maximization with `graph-tool`?](https://graph-tool.skewed.de/static/docs/stable/faq.html#is-it-possible-to-perform-modularity-maximization-with-graph-tool)
* [How do I cite graph-tool?](https://graph-tool.skewed.de/static/docs/stable/faq.html#how-do-i-cite-graph-tool)
References[#](https://graph-tool.skewed.de/static/docs/stable/index.html#references "Link to this heading")
------------------------------------------------------------------------------------------------------------
\[[1](https://graph-tool.skewed.de/static/docs/stable/index.html#id1)\
\]
Tiago P. Peixoto. Descriptive vs. Inferential Community Detection in Networks: Pitfalls, Myths and Half-Truths. _Elements in the Structure and Dynamics of Complex Networks_, July 2023. [arXiv:2112.00183](https://arxiv.org/abs/2112.00183)
, [doi:10.1017/9781009118897](https://doi.org/10.1017/9781009118897)
, [\[sci-hub\]](https://sci-hub.ru/10.1017/9781009118897)
.
Contents
---
# Cookbook guides — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/demos/index.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/demos/index.md "Suggest edit")
* [.md](https://graph-tool.skewed.de/static/docs/stable/_sources/demos/index.md "Download source file")
* .pdf
Cookbook guides
===============
Cookbook guides[#](https://graph-tool.skewed.de/static/docs/stable/demos/index.html#cookbook-guides "Link to this heading")
============================================================================================================================
Contents:
* [Inferring modular network structure](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html)
* [Background: Nonparametric statistical inference](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#background-nonparametric-statistical-inference)
* [Minimum description length (MDL)](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#minimum-description-length-mdl)
* [The stochastic block model (SBM)](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#the-stochastic-block-model-sbm)
* [The nested stochastic block model](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#the-nested-stochastic-block-model)
* [Inferring the best partition](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#inferring-the-best-partition)
* [Hierarchical partitions](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#hierarchical-partitions)
* [Refinements using merge-split MCMC](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#refinements-using-merge-split-mcmc)
* [Model selection](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#model-selection)
* [Sampling from the posterior distribution](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#sampling-from-the-posterior-distribution)
* [Hierarchical partitions](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#id18)
* [Characterizing the posterior distribution](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#characterizing-the-posterior-distribution)
* [Model class selection](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#model-class-selection)
* [Edge weights and covariates](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#edge-weights-and-covariates)
* [Model selection](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#id27)
* [Posterior sampling](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#posterior-sampling)
* [Layered networks](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#layered-networks)
* [Assortative community structure](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#assortative-community-structure)
* [Ordered community structure](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#ordered-community-structure)
* [References](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#references)
* [Uncertain network reconstruction](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html)
* [Measured networks](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html#measured-networks)
* [Heterogeneous errors](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html#heterogeneous-errors)
* [Extraneous error estimates](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html#extraneous-error-estimates)
* [Latent Poisson multigraphs](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html#latent-poisson-multigraphs)
* [Latent triadic closures](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html#latent-triadic-closures)
* [Edge prediction as binary classification](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html#edge-prediction-as-binary-classification)
* [References](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_direct/reconstruction.html#references)
* [Network reconstruction from dynamics and behavior](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_indirect/reconstruction.html)
* [Reconstruction with synthetic data](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_indirect/reconstruction.html#reconstruction-with-synthetic-data)
* [\\(L\_1\\) regularization](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_indirect/reconstruction.html#l-1-regularization)
* [Reconstruction with empirical data](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_indirect/reconstruction.html#reconstruction-with-empirical-data)
* [References](https://graph-tool.skewed.de/static/docs/stable/demos/reconstruction_indirect/reconstruction.html#references)
* [Animations with graph-tool](https://graph-tool.skewed.de/static/docs/stable/demos/animation/animation.html)
* [Simple interactive animations](https://graph-tool.skewed.de/static/docs/stable/demos/animation/animation.html#simple-interactive-animations)
* [SIRS epidemics](https://graph-tool.skewed.de/static/docs/stable/demos/animation/animation.html#sirs-epidemics)
* [Dynamic layout](https://graph-tool.skewed.de/static/docs/stable/demos/animation/animation.html#dynamic-layout)
* [Interactive visualizations](https://graph-tool.skewed.de/static/docs/stable/demos/animation/animation.html#interactive-visualizations)
* [Integration with matplotlib](https://graph-tool.skewed.de/static/docs/stable/demos/matplotlib/matplotlib.html)
* [Integration with `basemap`](https://graph-tool.skewed.de/static/docs/stable/demos/matplotlib/matplotlib.html#integration-with-basemap)
* [Writing extensions in C++](https://graph-tool.skewed.de/static/docs/stable/demos/cppextensions/cppextensions.html)
* [Range-based iteration over vertices and edges](https://graph-tool.skewed.de/static/docs/stable/demos/cppextensions/cppextensions.html#range-based-iteration-over-vertices-and-edges)
* [Extracting specific property maps](https://graph-tool.skewed.de/static/docs/stable/demos/cppextensions/cppextensions.html#extracting-specific-property-maps)
* [Checked and unchecked property maps](https://graph-tool.skewed.de/static/docs/stable/demos/cppextensions/cppextensions.html#checked-and-unchecked-property-maps)
* [References](https://graph-tool.skewed.de/static/docs/stable/demos/cppextensions/cppextensions.html#references)
---
# Parallel algorithms — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/parallel.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/parallel.md "Suggest edit")
* [.md](https://graph-tool.skewed.de/static/docs/stable/_sources/parallel.md "Download source file")
* .pdf
Parallel algorithms
===================
Contents
--------
Parallel algorithms[#](https://graph-tool.skewed.de/static/docs/stable/parallel.html#parallel-algorithms "Link to this heading")
=================================================================================================================================
`graph-tool` has support for shared memory parallelization via [OpenMP](https://en.wikipedia.org/wiki/OpenMP)
for many algorithms, as is indicated in their docstring.
OpenMP support is optional, and must be enabled during compilation. To check whether it is available, the function [`openmp_enabled()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_enabled.html#graph_tool.openmp_enabled "graph_tool.openmp_enabled")
can be used.
graph\_tool.openmp\_enabled()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_enabled)
Return `True` if OpenMP was enabled during compilation.
Note
By default, `graph-tool` will try to configure the [OpenMP wait policy](https://www.openmp.org/spec-html/5.0/openmpse55.html)
to “passive”, since this usually results in improved performance for the majority of algorithms.
In order to change this behavior, the following environment variable should be set before the Python interpreted is evoked:
export OMP\_WAIT\_POLICY\=active
or alternatively from Python before graph-tool is imported:
import os
os.environ\["OMP\_WAIT\_POLICY"\] \= "active"
Due to an OpenMP API limitation, this can no longer be changed after graph-tool has been imported.
Warning
If another library that uses OpenMP is imported before `graph-tool`, the wait policy will be set to the default value of “active”, which will no longer be able to be changed when `graph-tool` is first imported, or any time later. The only way to ensure that this policy is chosen is to set the environment variable before the Python interpreter is first evoked:
export OMP\_WAIT\_POLICY\=passive
It is recommended for user to set this value to guarantee the best performance with `graph-tool` in every circumstance.
Several parallelization parameters can be controlled at runtime, including the number of threads, the work sharing schedule, and the minimum number of nodes required for parallelization to be enabled.
graph\_tool.openmp\_get\_num\_threads()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_get_num_threads)
Return the number of OpenMP threads.
graph\_tool.openmp\_set\_num\_threads(_n_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_set_num_threads)
Set the number of OpenMP threads.
graph\_tool.openmp\_get\_schedule()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_get_schedule)
Return the runtime OpenMP schedule and chunk size. The schedule can by any of: `"static"`, `"dynamic"`, `"guided"`, `"auto"`.
graph\_tool.openmp\_set\_schedule(_schedule_, _chunk\=0_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_set_schedule)
Set the runtime OpenMP schedule and chunk size. The schedule can by any of: `"static"`, `"dynamic"`, `"guided"`, `"auto"`.
graph\_tool.openmp\_get\_thresh()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_get_thresh)
Return the minimum number of vertices necessary to enable parallelization.
graph\_tool.openmp\_set\_thresh(_n_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_set_thresh)
Set the the minimum number of vertices necessary to enable parallelization.
It’s possible to set these parameter temporarily using a context manager:
graph\_tool.openmp\_context(_nthreads\=None_, _schedule\=None_, _chunk\=0_, _thresh\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_context)
Return a context manager that sets the tuntime OpenMP parameters, and restores the original values when exited.
For example, to constrain temporarily the number of threads to 3 and use a “guided” scheduling one could do:
\>>> g \= gt.collection.data\["polblogs"\]
\>>> with gt.openmp\_context(nthreads\=3, schedule\="guided"):
... ret \= gt.pagerank(g)
Parallelization can be disabled altogether in the same way, but using `nthreads=1`.
The global interpreter lock (GIL)[#](https://graph-tool.skewed.de/static/docs/stable/parallel.html#the-global-interpreter-lock-gil "Link to this heading")
-----------------------------------------------------------------------------------------------------------------------------------------------------------
`graph-tool` releases Python’s [GIL](https://wiki.python.org/moin/GlobalInterpreterLock)
as soon as the C++ implementations are reached, even for algorithms that are not implemented in parallel with OpenMP. This means that Python’s [`threading`](https://docs.python.org/3/library/threading.html#module-threading "(in Python v3.13)")
functionally can be used with many functions to achieve parallelism. For example, the following code will run several calls of [`subgraph_isomorphism()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.subgraph_isomorphism.html#graph_tool.topology.subgraph_isomorphism "graph_tool.topology.subgraph_isomorphism")
in parallel using 16 threads, which each individual call running sequentially:
\>>> from concurrent.futures import ThreadPoolExecutor
\>>> g \= gt.collection.data\["netscience"\]
\>>> def find\_sub():
... u \= gt.random\_graph(11, lambda: 4, directed\=False, model\="erdos")
... gt.subgraph\_isomorphism(u, g, max\_n\=100)
\>>> with ThreadPoolExecutor(max\_workers\=16) as executor:
... futures \= \[executor.submit(find\_sub) for i in range(16)\]
... for future in futures:
... future.result()
The same kind of functionality can be achieved with [`multiprocessing`](https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing "(in Python v3.13)")
with a nearly identical interface, but the above offers smaller overhead, since no inter-process communication is needed.
Contents
---
# graph_tool — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/graph_tool.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/graph_tool.rst "Download source file")
* .pdf
graph\_tool
===========
Contents
--------
`graph_tool`[#](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#graph-tool "Link to this heading")
===================================================================================================================
This is the core module providing the fundamental data structures and functions.
Fundamental classes[#](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#fundamental-classes "Link to this heading")
-----------------------------------------------------------------------------------------------------------------------------------
| | |
| --- | --- |
| [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph") | General multigraph class. |
| [`GraphView`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView "graph_tool.GraphView") | A view of selected vertices or edges of another graph. |
| [`Vertex`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex "graph_tool.Vertex") | Vertex descriptor. |
| [`Edge`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#graph_tool.Edge "graph_tool.Edge") | Edge descriptor. |
Property Maps[#](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#property-maps "Link to this heading")
-----------------------------------------------------------------------------------------------------------------------
| | |
| --- | --- |
| [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap") | This base class provides a mapping from vertices, edges or whole graphs to arbitrary properties. |
| [`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap") | This class provides a mapping from vertices to arbitrary properties. |
| [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap") | This class provides a mapping from edges to arbitrary properties. |
| [`GraphPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap "graph_tool.GraphPropertyMap") | This class provides a mapping from graphs to arbitrary properties. |
| [`PropertyArray`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "graph_tool.PropertyArray") | This is a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
subclass which keeps a reference of its [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
owner. |
| [`group_vector_property`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.group_vector_property.html#graph_tool.group_vector_property "graph_tool.group_vector_property") | Group list of properties `props` into a vector property map of the same type. |
| [`ungroup_vector_property`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.ungroup_vector_property.html#graph_tool.ungroup_vector_property "graph_tool.ungroup_vector_property") | Ungroup vector property map `vprop` into a list of non-vector property maps. |
| [`map_property_values`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.map_property_values.html#graph_tool.map_property_values "graph_tool.map_property_values") | Map the values of `src_prop` to `tgt_prop` according to the mapping function `map_func`. |
| [`infect_vertex_property`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.infect_vertex_property.html#graph_tool.infect_vertex_property "graph_tool.infect_vertex_property") | Propagate the prop values of vertices with value val to all their out-neighbors. |
| [`edge_endpoint_property`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.edge_endpoint_property.html#graph_tool.edge_endpoint_property "graph_tool.edge_endpoint_property") | Return an edge property map corresponding to the vertex property prop of either the target and source of the edge, according to endpoint. |
| [`incident_edges_op`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.incident_edges_op.html#graph_tool.incident_edges_op "graph_tool.incident_edges_op") | Return a vertex property map corresponding to a specific operation (sum, product, min or max) on the edge property eprop of incident edges on each vertex, following the direction given by direction. |
| [`perfect_prop_hash`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.perfect_prop_hash.html#graph_tool.perfect_prop_hash "graph_tool.perfect_prop_hash") | Given a list of property maps props of the same type, a derived list of property maps with integral type htype is returned, where each value is replaced by a perfect (i.e. unique) hash value. |
| [`value_types`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.value_types.html#graph_tool.value_types "graph_tool.value_types") | Return a list of possible properties value types. |
Graph IO[#](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#graph-io "Link to this heading")
-------------------------------------------------------------------------------------------------------------
| | |
| --- | --- |
| [`load_graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.load_graph.html#graph_tool.load_graph "graph_tool.load_graph") | Load a graph from `file_name` (which can be either a string or a file-like object). |
| [`load_graph_from_csv`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.load_graph_from_csv.html#graph_tool.load_graph_from_csv "graph_tool.load_graph_from_csv") | Load a graph from a [`csv`](https://docs.python.org/3/library/csv.html#module-csv "(in Python v3.13)")
file containing a list of edges and edge properties. |
OpenMP configuration[#](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#openmp-configuration "Link to this heading")
-------------------------------------------------------------------------------------------------------------------------------------
| | |
| --- | --- |
| [`openmp_enabled`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_enabled.html#graph_tool.openmp_enabled "graph_tool.openmp_enabled") | Return `True` if OpenMP was enabled during compilation. |
| [`openmp_get_num_threads`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_num_threads.html#graph_tool.openmp_get_num_threads "graph_tool.openmp_get_num_threads") | Return the number of OpenMP threads. |
| [`openmp_set_num_threads`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_num_threads.html#graph_tool.openmp_set_num_threads "graph_tool.openmp_set_num_threads") | Set the number of OpenMP threads. |
| [`openmp_get_schedule`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_schedule.html#graph_tool.openmp_get_schedule "graph_tool.openmp_get_schedule") | Return the runtime OpenMP schedule and chunk size. |
| [`openmp_set_schedule`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_schedule.html#graph_tool.openmp_set_schedule "graph_tool.openmp_set_schedule") | Set the runtime OpenMP schedule and chunk size. |
| [`openmp_get_thresh`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_thresh.html#graph_tool.openmp_get_thresh "graph_tool.openmp_get_thresh") | Return the minimum number of vertices necessary to enable parallelization. |
| [`openmp_set_thresh`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_thresh.html#graph_tool.openmp_set_thresh "graph_tool.openmp_set_thresh") | Set the the minimum number of vertices necessary to enable parallelization. |
System information[#](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#system-information "Link to this heading")
---------------------------------------------------------------------------------------------------------------------------------
| | |
| --- | --- |
| [`show_config`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.show_config.html#graph_tool.show_config "graph_tool.show_config") | Show `graph_tool` build configuration. |
Contents
---
# Submodules — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/modules.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/modules.md "Suggest edit")
* [.md](https://graph-tool.skewed.de/static/docs/stable/_sources/modules.md "Download source file")
* .pdf
Submodules
==========
Submodules[#](https://graph-tool.skewed.de/static/docs/stable/modules.html#submodules "Link to this heading")
==============================================================================================================
`graph-tool` is subdivided into the following submodules:
* [`graph_tool`](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html)
* [Graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html)
* [GraphView](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html)
* [Vertex](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html)
* [Edge](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html)
* [PropertyMap](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html)
* [VertexPropertyMap](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html)
* [EdgePropertyMap](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html)
* [GraphPropertyMap](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html)
* [PropertyArray](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html)
* [group\_vector\_property](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.group_vector_property.html)
* [ungroup\_vector\_property](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.ungroup_vector_property.html)
* [map\_property\_values](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.map_property_values.html)
* [infect\_vertex\_property](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.infect_vertex_property.html)
* [edge\_endpoint\_property](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.edge_endpoint_property.html)
* [incident\_edges\_op](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.incident_edges_op.html)
* [perfect\_prop\_hash](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.perfect_prop_hash.html)
* [value\_types](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.value_types.html)
* [load\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.load_graph.html)
* [load\_graph\_from\_csv](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.load_graph_from_csv.html)
* [openmp\_enabled](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_enabled.html)
* [openmp\_get\_num\_threads](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_num_threads.html)
* [openmp\_set\_num\_threads](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_num_threads.html)
* [openmp\_get\_schedule](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_schedule.html)
* [openmp\_set\_schedule](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_schedule.html)
* [openmp\_get\_thresh](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_thresh.html)
* [openmp\_set\_thresh](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_thresh.html)
* [show\_config](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.show_config.html)
* [`graph_tool.centrality`](https://graph-tool.skewed.de/static/docs/stable/centrality.html)
* [pagerank](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html)
* [betweenness](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.betweenness.html)
* [central\_point\_dominance](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.central_point_dominance.html)
* [closeness](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.closeness.html)
* [eigenvector](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.eigenvector.html)
* [katz](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.katz.html)
* [hits](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.hits.html)
* [eigentrust](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.eigentrust.html)
* [trust\_transitivity](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.trust_transitivity.html)
* [`graph_tool.clustering`](https://graph-tool.skewed.de/static/docs/stable/clustering.html)
* [local\_clustering](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.clustering.local_clustering.html)
* [global\_clustering](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.clustering.global_clustering.html)
* [extended\_clustering](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.clustering.extended_clustering.html)
* [motifs](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.clustering.motifs.html)
* [motif\_significance](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.clustering.motif_significance.html)
* [`graph_tool.collection`](https://graph-tool.skewed.de/static/docs/stable/collection.html)
* [LCF\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.LCF_graph.html)
* [bull\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.bull_graph.html)
* [chvatal\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.chvatal_graph.html)
* [cubical\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.cubical_graph.html)
* [desargues\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.desargues_graph.html)
* [diamond\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.diamond_graph.html)
* [dodecahedral\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.dodecahedral_graph.html)
* [frucht\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.frucht_graph.html)
* [heawood\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.heawood_graph.html)
* [hoffman\_singleton\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.hoffman_singleton_graph.html)
* [house\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.house_graph.html)
* [icosahedral\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.icosahedral_graph.html)
* [krackhardt\_kite\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.krackhardt_kite_graph.html)
* [moebius\_kantor\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.moebius_kantor_graph.html)
* [octahedral\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.octahedral_graph.html)
* [pappus\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.pappus_graph.html)
* [petersen\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.petersen_graph.html)
* [sedgewick\_maze\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.sedgewick_maze_graph.html)
* [tetrahedral\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.tetrahedral_graph.html)
* [truncated\_cube\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.truncated_cube_graph.html)
* [truncated\_tetrahedron\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.truncated_tetrahedron_graph.html)
* [tutte\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.collection.tutte_graph.html)
* [`graph_tool.correlations`](https://graph-tool.skewed.de/static/docs/stable/correlations.html)
* [assortativity](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.correlations.assortativity.html)
* [scalar\_assortativity](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.correlations.scalar_assortativity.html)
* [corr\_hist](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.correlations.corr_hist.html)
* [combined\_corr\_hist](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.correlations.combined_corr_hist.html)
* [avg\_neighbor\_corr](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.correlations.avg_neighbor_corr.html)
* [avg\_combined\_corr](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.correlations.avg_combined_corr.html)
* [`graph_tool.dynamics`](https://graph-tool.skewed.de/static/docs/stable/dynamics.html)
* [DiscreteStateBase](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.DiscreteStateBase.html)
* [EpidemicStateBase](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.EpidemicStateBase.html)
* [SIState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.SIState.html)
* [SISState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.SISState.html)
* [SIRState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.SIRState.html)
* [SIRSState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.SIRSState.html)
* [VoterState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.VoterState.html)
* [MajorityVoterState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.MajorityVoterState.html)
* [BinaryThresholdState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.BinaryThresholdState.html)
* [IsingGlauberState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.IsingGlauberState.html)
* [CIsingGlauberState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.CIsingGlauberState.html)
* [IsingMetropolisState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.IsingMetropolisState.html)
* [PottsGlauberState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.PottsGlauberState.html)
* [PottsMetropolisState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.PottsMetropolisState.html)
* [AxelrodState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.AxelrodState.html)
* [BooleanState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.BooleanState.html)
* [KirmanState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.KirmanState.html)
* [NormalState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.NormalState.html)
* [LinearNormalState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.LinearNormalState.html)
* [ContinuousStateBase](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.ContinuousStateBase.html)
* [LinearState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.LinearState.html)
* [LVState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.LVState.html)
* [KuramotoState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.KuramotoState.html)
* [BPBaseState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.BPBaseState.html)
* [GenPottsBPState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.GenPottsBPState.html)
* [IsingBPState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.IsingBPState.html)
* [NormalBPState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.dynamics.NormalBPState.html)
* [`graph_tool.draw`](https://graph-tool.skewed.de/static/docs/stable/draw.html)
* [sfdp\_layout](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.sfdp_layout.html)
* [fruchterman\_reingold\_layout](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.fruchterman_reingold_layout.html)
* [arf\_layout](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.arf_layout.html)
* [radial\_tree\_layout](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.radial_tree_layout.html)
* [planar\_layout](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.planar_layout.html)
* [random\_layout](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.random_layout.html)
* [graph\_draw](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.graph_draw.html)
* [draw\_hierarchy](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.draw_hierarchy.html)
* [graphviz\_draw](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.graphviz_draw.html)
* [prop\_to\_size](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.prop_to_size.html)
* [get\_hierarchy\_control\_points](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.get_hierarchy_control_points.html)
* [cairo\_draw](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.cairo_draw.html)
* [interactive\_window](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.interactive_window.html)
* [GraphWidget](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.GraphWidget.html)
* [GraphWindow](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.GraphWindow.html)
* [GraphArtist](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.GraphArtist.html)
* [`graph_tool.flow`](https://graph-tool.skewed.de/static/docs/stable/flow.html)
* [edmonds\_karp\_max\_flow](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.flow.edmonds_karp_max_flow.html)
* [push\_relabel\_max\_flow](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.flow.push_relabel_max_flow.html)
* [boykov\_kolmogorov\_max\_flow](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.flow.boykov_kolmogorov_max_flow.html)
* [min\_st\_cut](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.flow.min_st_cut.html)
* [min\_cut](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.flow.min_cut.html)
* [`graph_tool.generation`](https://graph-tool.skewed.de/static/docs/stable/generation.html)
* [random\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.random_graph.html)
* [random\_rewire](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.random_rewire.html)
* [add\_random\_edges](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.add_random_edges.html)
* [remove\_random\_edges](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.remove_random_edges.html)
* [generate\_triadic\_closure](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.generate_triadic_closure.html)
* [price\_network](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.price_network.html)
* [generate\_sbm](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.generate_sbm.html)
* [generate\_maxent\_sbm](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.generate_maxent_sbm.html)
* [solve\_sbm\_fugacities](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.solve_sbm_fugacities.html)
* [generate\_knn](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.generate_knn.html)
* [geometric\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.geometric_graph.html)
* [triangulation](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.triangulation.html)
* [predecessor\_tree](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.predecessor_tree.html)
* [line\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.line_graph.html)
* [condensation\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.condensation_graph.html)
* [contract\_parallel\_edges](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.contract_parallel_edges.html)
* [remove\_parallel\_edges](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.remove_parallel_edges.html)
* [expand\_parallel\_edges](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.expand_parallel_edges.html)
* [label\_parallel\_edges](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.label_parallel_edges.html)
* [remove\_self\_loops](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.remove_self_loops.html)
* [label\_self\_loops](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.label_self_loops.html)
* [graph\_projection](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.graph_projection.html)
* [graph\_merge](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.graph_merge.html)
* [graph\_union](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.graph_union.html)
* [graph\_difference](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.graph_difference.html)
* [graph\_sym\_difference](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.graph_sym_difference.html)
* [graph\_intersection](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.graph_intersection.html)
* [lattice](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.lattice.html)
* [complete\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.complete_graph.html)
* [circular\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.generation.circular_graph.html)
* [`graph_tool.inference`](https://graph-tool.skewed.de/static/docs/stable/inference.html)
* [minimize\_blockmodel\_dl](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.minimize_blockmodel_dl.html)
* [minimize\_nested\_blockmodel\_dl](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.minimize_nested_blockmodel_dl.html)
* [BlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.BlockState.html)
* [OverlapBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.OverlapBlockState.html)
* [LayeredBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.LayeredBlockState.html)
* [NestedBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.NestedBlockState.html)
* [PPBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.PPBlockState.html)
* [RankedBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.RankedBlockState.html)
* [ModularityState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.ModularityState.html)
* [NormCutState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.NormCutState.html)
* [TemperingState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.TemperingState.html)
* [CliqueState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.CliqueState.html)
* [EntropyState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.EntropyState.html)
* [MCMCState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.MCMCState.html)
* [MultiflipMCMCState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.MultiflipMCMCState.html)
* [MultilevelMCMCState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.MultilevelMCMCState.html)
* [GibbsMCMCState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.GibbsMCMCState.html)
* [MulticanonicalMCMCState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.MulticanonicalMCMCState.html)
* [ExhaustiveSweepState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.ExhaustiveSweepState.html)
* [DrawBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.DrawBlockState.html)
* [mcmc\_equilibrate](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.mcmc_equilibrate.html)
* [mcmc\_anneal](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.mcmc_anneal.html)
* [multicanonical\_equilibrate](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.multicanonical_equilibrate.html)
* [MulticanonicalState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.MulticanonicalState.html)
* [PartitionModeState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.PartitionModeState.html)
* [ModeClusterState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.ModeClusterState.html)
* [PartitionCentroidState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.PartitionCentroidState.html)
* [partition\_overlap](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.partition_overlap.html)
* [nested\_partition\_overlap](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.nested_partition_overlap.html)
* [variation\_information](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.variation_information.html)
* [mutual\_information](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.mutual_information.html)
* [reduced\_mutual\_information](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.reduced_mutual_information.html)
* [contingency\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.contingency_graph.html)
* [shuffle\_partition\_labels](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.shuffle_partition_labels.html)
* [order\_partition\_labels](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.order_partition_labels.html)
* [order\_nested\_partition\_labels](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.order_nested_partition_labels.html)
* [align\_partition\_labels](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.align_partition_labels.html)
* [align\_nested\_partition\_labels](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.align_nested_partition_labels.html)
* [partition\_overlap\_center](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.partition_overlap_center.html)
* [nested\_partition\_overlap\_center](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.nested_partition_overlap_center.html)
* [nested\_partition\_clear\_null](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.nested_partition_clear_null.html)
* [contiguous\_map](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.contiguous_map.html)
* [nested\_contiguous\_map](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.nested_contiguous_map.html)
* [mf\_entropy](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.mf_entropy.html)
* [bethe\_entropy](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.bethe_entropy.html)
* [microstate\_entropy](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.microstate_entropy.html)
* [marginal\_multigraph\_entropy](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.marginal_multigraph_entropy.html)
* [half\_edge\_graph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.half_edge_graph.html)
* [get\_block\_edge\_gradient](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.get_block_edge_gradient.html)
* [PartitionHist](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.PartitionHist.html)
* [BlockPairHist](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.BlockPairHist.html)
* [LatentLayerBaseState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.LatentLayerBaseState.html)
* [LatentMultigraphBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.LatentMultigraphBlockState.html)
* [LatentClosureBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.LatentClosureBlockState.html)
* [MeasuredBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.MeasuredBlockState.html)
* [MeasuredClosureBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.MeasuredClosureBlockState.html)
* [MixedMeasuredBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.MixedMeasuredBlockState.html)
* [UncertainBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.UncertainBlockState.html)
* [UncertainBaseState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.UncertainBaseState.html)
* [latent\_multigraph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.latent_multigraph.html)
* [DynamicsBlockStateBase](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.DynamicsBlockStateBase.html)
* [BPBlockStateBase](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.BPBlockStateBase.html)
* [PseudoNormalBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.PseudoNormalBlockState.html)
* [NormalGlauberBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.NormalGlauberBlockState.html)
* [LinearNormalBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.LinearNormalBlockState.html)
* [LVBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.LVBlockState.html)
* [EpidemicsBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.EpidemicsBlockState.html)
* [IsingBlockStateBase](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.IsingBlockStateBase.html)
* [IsingGlauberBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.IsingGlauberBlockState.html)
* [CIsingGlauberBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.CIsingGlauberBlockState.html)
* [PseudoIsingBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.PseudoIsingBlockState.html)
* [PseudoCIsingBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.PseudoCIsingBlockState.html)
* [PottsBlockStateBase](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.PottsBlockStateBase.html)
* [PottsGlauberBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.PottsGlauberBlockState.html)
* [PseudoPottsBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.PseudoPottsBlockState.html)
* [PottsState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.PottsState.html)
* [EMBlockState](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.EMBlockState.html)
* [em\_infer](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.em_infer.html)
* [modularity](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.modularity.html)
* [`graph_tool.search`](https://graph-tool.skewed.de/static/docs/stable/search_module.html)
* [bfs\_search](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.bfs_search.html)
* [bfs\_iterator](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.bfs_iterator.html)
* [dfs\_search](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.dfs_search.html)
* [dfs\_iterator](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.dfs_iterator.html)
* [dijkstra\_search](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.dijkstra_search.html)
* [dijkstra\_iterator](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.dijkstra_iterator.html)
* [astar\_search](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.astar_search.html)
* [astar\_iterator](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.astar_iterator.html)
* [bellman\_ford\_search](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.bellman_ford_search.html)
* [BFSVisitor](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.BFSVisitor.html)
* [DFSVisitor](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.DFSVisitor.html)
* [DijkstraVisitor](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.DijkstraVisitor.html)
* [BellmanFordVisitor](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.BellmanFordVisitor.html)
* [AStarVisitor](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.AStarVisitor.html)
* [StopSearch](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.search.StopSearch.html)
* [`graph_tool.spectral`](https://graph-tool.skewed.de/static/docs/stable/spectral.html)
* [adjacency](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.spectral.adjacency.html)
* [laplacian](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.spectral.laplacian.html)
* [incidence](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.spectral.incidence.html)
* [transition](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.spectral.transition.html)
* [modularity\_matrix](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.spectral.modularity_matrix.html)
* [hashimoto](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.spectral.hashimoto.html)
* [AdjacencyOperator](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.spectral.AdjacencyOperator.html)
* [LaplacianOperator](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.spectral.LaplacianOperator.html)
* [IncidenceOperator](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.spectral.IncidenceOperator.html)
* [TransitionOperator](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.spectral.TransitionOperator.html)
* [HashimotoOperator](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.spectral.HashimotoOperator.html)
* [CompactHashimotoOperator](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.spectral.CompactHashimotoOperator.html)
* [`graph_tool.stats`](https://graph-tool.skewed.de/static/docs/stable/stats.html)
* [vertex\_hist](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.stats.vertex_hist.html)
* [edge\_hist](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.stats.edge_hist.html)
* [vertex\_average](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.stats.vertex_average.html)
* [edge\_average](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.stats.edge_average.html)
* [distance\_histogram](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.stats.distance_histogram.html)
* [`graph_tool.topology`](https://graph-tool.skewed.de/static/docs/stable/topology.html)
* [shortest\_distance](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.shortest_distance.html)
* [shortest\_path](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.shortest_path.html)
* [random\_shortest\_path](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.random_shortest_path.html)
* [count\_shortest\_paths](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.count_shortest_paths.html)
* [all\_shortest\_paths](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.all_shortest_paths.html)
* [all\_predecessors](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.all_predecessors.html)
* [all\_paths](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.all_paths.html)
* [all\_circuits](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.all_circuits.html)
* [pseudo\_diameter](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.pseudo_diameter.html)
* [similarity](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.similarity.html)
* [vertex\_similarity](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.vertex_similarity.html)
* [isomorphism](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.isomorphism.html)
* [subgraph\_isomorphism](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.subgraph_isomorphism.html)
* [mark\_subgraph](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.mark_subgraph.html)
* [max\_cliques](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.max_cliques.html)
* [max\_cardinality\_matching](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.max_cardinality_matching.html)
* [max\_independent\_vertex\_set](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.max_independent_vertex_set.html)
* [min\_spanning\_tree](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.min_spanning_tree.html)
* [random\_spanning\_tree](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.random_spanning_tree.html)
* [dominator\_tree](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.dominator_tree.html)
* [topological\_sort](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.topological_sort.html)
* [transitive\_closure](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.transitive_closure.html)
* [label\_components](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.label_components.html)
* [label\_biconnected\_components](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.label_biconnected_components.html)
* [label\_largest\_component](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.label_largest_component.html)
* [extract\_largest\_component](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.extract_largest_component.html)
* [label\_out\_component](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.label_out_component.html)
* [vertex\_percolation](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.vertex_percolation.html)
* [edge\_percolation](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.edge_percolation.html)
* [kcore\_decomposition](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.kcore_decomposition.html)
* [is\_bipartite](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.is_bipartite.html)
* [is\_DAG](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.is_DAG.html)
* [is\_planar](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.is_planar.html)
* [make\_maximal\_planar](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.make_maximal_planar.html)
* [edge\_reciprocity](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.edge_reciprocity.html)
* [tsp\_tour](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.tsp_tour.html)
* [sequential\_vertex\_coloring](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.topology.sequential_vertex_coloring.html)
* [`graph_tool.util`](https://graph-tool.skewed.de/static/docs/stable/util.html)
* [find\_vertex](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.util.find_vertex.html)
* [find\_vertex\_range](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.util.find_vertex_range.html)
* [find\_edge](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.util.find_edge.html)
* [find\_edge\_range](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.util.find_edge_range.html)
---
# Vertex — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.Vertex.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.Vertex.rst "Download source file")
* .pdf
Vertex
======
Contents
--------
Vertex[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#vertex "Link to this heading")
============================================================================================================================
_class_ graph\_tool.Vertex[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex "Link to this definition")
Bases: `instance`
Vertex descriptor.
This class represents a vertex in a [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
instance.
[`Vertex`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex "graph_tool.Vertex")
instances are hashable, and are convertible to integers, corresponding to its index (see [`vertex_index`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex_index "graph_tool.Graph.vertex_index")
).
Raises an exception This class cannot be instantiated from Python
Methods
| | |
| --- | --- |
| [`all_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.all_edges "graph_tool.Vertex.all_edges")
() | Return an iterator over all edges (both in or out). |
| [`all_neighbors`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.all_neighbors "graph_tool.Vertex.all_neighbors")
() | Return an iterator over all neighbors (both in or out). |
| [`in_degree`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_degree "graph_tool.Vertex.in_degree")
(\[weight\]) | Return the in-degree of the vertex. |
| [`in_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_edges "graph_tool.Vertex.in_edges") | Return an iterator over the in-edges. |
| [`in_neighbors`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_neighbors "graph_tool.Vertex.in_neighbors")
() | Return an iterator over the in-neighbors. |
| [`is_valid`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.is_valid "graph_tool.Vertex.is_valid") | Returns `True` if the descriptor corresponds to an existing vertex in the graph, `False` otherwise. |
| [`out_degree`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_degree "graph_tool.Vertex.out_degree")
(\[weight\]) | Return the out-degree of the vertex. |
| [`out_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_edges "graph_tool.Vertex.out_edges") | Return an iterator over the out-edges. |
| [`out_neighbors`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_neighbors "graph_tool.Vertex.out_neighbors")
() | Return an iterator over the out-neighbors. |
all\_edges()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.all_edges "Link to this definition")
Return an iterator over all edges (both in or out).
all\_neighbors()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.all_neighbors "Link to this definition")
Return an iterator over all neighbors (both in or out).
in\_degree(_weight\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_degree "Link to this definition")
Return the in-degree of the vertex. If provided, `weight` should be a scalar edge [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
, and the in-degree will correspond to the sum of the weights of the in-edges.
in\_edges()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_edges "Link to this definition")
Return an iterator over the in-edges.
in\_neighbors()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_neighbors "Link to this definition")
Return an iterator over the in-neighbors.
is\_valid()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.is_valid "Link to this definition")
Returns `True` if the descriptor corresponds to an existing vertex in the graph, `False` otherwise.
out\_degree(_weight\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_degree "Link to this definition")
Return the out-degree of the vertex. If provided, `weight` should be a scalar edge [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
, and the out-degree will correspond to the sum of the weights of the out-edges.
out\_edges()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_edges "Link to this definition")
Return an iterator over the out-edges.
out\_neighbors()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_neighbors "Link to this definition")
Return an iterator over the out-neighbors.
Contents
---
# Edge — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.Edge.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.Edge.rst "Download source file")
* .pdf
Edge
====
Contents
--------
Edge[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#edge "Link to this heading")
======================================================================================================================
_class_ graph\_tool.Edge[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#graph_tool.Edge "Link to this definition")
Bases: `instance`
Edge descriptor.
This class represents an edge in a [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
.
[`Edge`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#graph_tool.Edge "graph_tool.Edge")
instances are hashable, iterable and thus are convertible to a tuple, which contains the source and target vertices.
Raises an exception This class cannot be instantiated from Python
Methods
| | |
| --- | --- |
| [`is_valid`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#graph_tool.Edge.is_valid "graph_tool.Edge.is_valid") | Returns `True` if the descriptor corresponds to an existing edge in the graph, `False` otherwise. |
| [`source`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#graph_tool.Edge.source "graph_tool.Edge.source") | Returns the source of the edge (a [`Vertex`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex "graph_tool.Vertex")
instance). |
| [`target`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#graph_tool.Edge.target "graph_tool.Edge.target") | Returns the target of the edge (a [`Vertex`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex "graph_tool.Vertex")
instance). |
is\_valid()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#graph_tool.Edge.is_valid "Link to this definition")
Returns `True` if the descriptor corresponds to an existing edge in the graph, `False` otherwise.
source()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#graph_tool.Edge.source "Link to this definition")
Returns the source of the edge (a [`Vertex`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex "graph_tool.Vertex")
instance).
target()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#graph_tool.Edge.target "Link to this definition")
Returns the target of the edge (a [`Vertex`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex "graph_tool.Vertex")
instance).
Contents
---
# VertexPropertyMap — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.VertexPropertyMap.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.VertexPropertyMap.rst "Download source file")
* .pdf
VertexPropertyMap
=================
Contents
--------
VertexPropertyMap[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#vertexpropertymap "Link to this heading")
=============================================================================================================================================================
_class_ graph\_tool.VertexPropertyMap(_pmap_, _g_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#VertexPropertyMap)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "Link to this definition")
Bases: [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
This class provides a mapping from vertices to arbitrary properties.
See [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-maps)
and [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
for more details.
Methods
| | |
| --- | --- |
| [`coerce_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.coerce_type "graph_tool.VertexPropertyMap.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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.copy "graph_tool.VertexPropertyMap.copy")
(\[value\_type, full\]) | Return a copy of the property map. |
| [`data_ptr`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.data_ptr "graph_tool.VertexPropertyMap.data_ptr")
() | Return the pointer to memory where the data resides. |
| [`get_2d_array`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.get_2d_array "graph_tool.VertexPropertyMap.get_2d_array")
(\[pos, dtype\]) | 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, which contains a copy of all entries of the vector-valued property map. |
| [`get_array`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.get_array "graph_tool.VertexPropertyMap.get_array")
() | Get a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
subclass ([`PropertyArray`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "graph_tool.PropertyArray")
) pointint to the property values. |
| [`get_graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.get_graph "graph_tool.VertexPropertyMap.get_graph")
() | Get the graph class to which the map refers. |
| [`is_writable`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.is_writable "graph_tool.VertexPropertyMap.is_writable")
() | Return True if the property is writable. |
| [`key_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.key_type "graph_tool.VertexPropertyMap.key_type")
() | Return the key type of the map. |
| [`python_value_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.python_value_type "graph_tool.VertexPropertyMap.python_value_type")
() | Return the python-compatible value type of the map. |
| [`reserve`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.reserve "graph_tool.VertexPropertyMap.reserve")
(size) | Reserve enough space for `size` elements in underlying container. |
| [`resize`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.resize "graph_tool.VertexPropertyMap.resize")
(size) | Resize the underlying container to contain exactly `size` elements. |
| [`set_2d_array`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.set_2d_array "graph_tool.VertexPropertyMap.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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.set_value "graph_tool.VertexPropertyMap.set_value")
(val) | Sets all values in the property map to the same `val`. |
| [`set_values`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.set_values "graph_tool.VertexPropertyMap.set_values")
(vals) | Sets values in the property map to the iterable `vals`. |
| [`shrink_to_fit`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.shrink_to_fit "graph_tool.VertexPropertyMap.shrink_to_fit")
() | Shrink size of underlying container to accommodate only the necessary amount, and thus potentially freeing memory. |
| [`swap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.swap "graph_tool.VertexPropertyMap.swap")
(other) | Swap internal storage with `other`. |
| [`t`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.t "graph_tool.VertexPropertyMap.t")
(f\[, value\_type, no\_array, inplace\]) | Alias to [`transform()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.transform "graph_tool.PropertyMap.transform")
. |
| [`transform`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.transform "graph_tool.VertexPropertyMap.transform")
(f\[, value\_type, no\_array, inplace\]) | Return a copy of the property map with the values transformed by the user-supplied function `f`. |
| [`value_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.value_type "graph_tool.VertexPropertyMap.value_type")
() | Return the value type of the map. |
Attributes
| | |
| --- | --- |
| [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.a "graph_tool.VertexPropertyMap.a") | Shortcut to the [`get_array()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_array "graph_tool.PropertyMap.get_array")
method as an attribute. |
| [`fa`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.fa "graph_tool.VertexPropertyMap.fa") | The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, but instead an _indexed_ array is returned, which contains only entries for vertices/edges which are not filtered out. |
| [`ma`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.ma "graph_tool.VertexPropertyMap.ma") | The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, but instead a [`numpy.ma.MaskedArray`](https://numpy.org/doc/stable/reference/maskedarray.baseclass.html#numpy.ma.MaskedArray "(in NumPy v2.3)")
object is returned, which contains only entries for vertices/edges which are not filtered out. |
coerce\_type(_full\=True_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.coerce_type "Link to this definition")
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_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.copy "Link to this definition")
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()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.data_ptr "Link to this definition")
Return the pointer to memory where the data resides.
get\_2d\_array(_pos\=None_, _dtype\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.get_2d_array "Link to this definition")
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, which 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.
If `pos` is not given (the default), then it will be assumed to correspond to the entire range of the first entry in the map.
The parameter `dtype` determines the desired data-type for the array. If not given, it will be determined automatically (by applying promotion rules when necessary.)
get\_array()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.get_array "Link to this definition")
Get a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
subclass ([`PropertyArray`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "graph_tool.PropertyArray")
) pointint to 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()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_2d_array "graph_tool.PropertyMap.get_2d_array")
and [`set_2d_array()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.set_2d_array "graph_tool.PropertyMap.set_2d_array")
member functions.
Warning
This function does not copy the data from the property map, and therefore runs in \\(O(1)\\) time.
As a consequence, 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()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.get_graph "Link to this definition")
Get the graph class to which the map refers.
is\_writable()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.is_writable "Link to this definition")
Return True if the property is writable.
key\_type()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.key_type "Link to this definition")
Return the key type of the map. Either ‘g’, ‘v’ or ‘e’.
python\_value\_type()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.python_value_type "Link to this definition")
Return the python-compatible value type of the map.
reserve(_size_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.reserve "Link to this definition")
Reserve enough space for `size` elements in underlying container. If the original size is already equal or larger, nothing will happen.
resize(_size_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.resize "Link to this definition")
Resize the underlying container to contain exactly `size` elements.
set\_2d\_array(_a_, _pos\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.set_2d_array "Link to this definition")
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_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.set_value "Link to this definition")
Sets all values in the property map to the same `val`.
set\_values(_vals_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.set_values "Link to this definition")
Sets values in the property map to the iterable `vals`.
shrink\_to\_fit()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.shrink_to_fit "Link to this definition")
Shrink size of underlying container to accommodate only the necessary amount, and thus potentially freeing memory.
swap(_other_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.swap "Link to this definition")
Swap internal storage with `other`.
t(_f_, _value\_type\=None_, _no\_array\=False_, _inplace\=False_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.t "Link to this definition")
Alias to [`transform()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.transform "graph_tool.PropertyMap.transform")
.
transform(_f_, _value\_type\=None_, _no\_array\=False_, _inplace\=False_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.transform "Link to this definition")
Return a copy of the property map with the values transformed by the user-supplied function `f`. If given, `value_type` specifies the value type for the new property map.
If the value type of the original map allows, the values will be passed to `f` as a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
, unless no\_array is `True`. Otherwise, they will be passed individually.
If `inplace == True` the transformation happens in-place, without copying the property map. In this case the parameter `value_type` is ignored.
value\_type()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.value_type "Link to this definition")
Return the value type of the map.
a[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.a "Link to this definition")
Shortcut to the [`get_array()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_array "graph_tool.PropertyMap.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[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.fa "Link to this definition")
The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute.
Warning
Because [advanced indexing](https://numpy.org/doc/stable/user/basics.indexing.html#advanced-indexing "(in NumPy v2.3)")
is triggered, a **copy** of the array is returned, not a view, as is the case for the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute. Nevertheless, the assignment of values to the _whole_ array at once works as expected.
Importantly, this means that this operation runs in time \\(O(N)\\) or O(N + E) for node and edge properties, respectively, where \\(N\\) is the number of vertices and \\(E\\) the number of edges in the unfiltered graph, and therefore can be significantly slower than using the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, which runs in time \\(O(1)\\).
ma[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap.ma "Link to this definition")
The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, but instead a [`numpy.ma.MaskedArray`](https://numpy.org/doc/stable/reference/maskedarray.baseclass.html#numpy.ma.MaskedArray "(in NumPy v2.3)")
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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "graph_tool.PropertyArray")
is returned, which is identical to the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute.
Warning
Unlike [`fa`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.fa "graph_tool.PropertyMap.fa")
, the masked array does _not_ copy the property map values.
This function runs in time \\(O(N)\\) or O(N + E) for node and edge properties, respectively, where \\(N\\) is the number of vertices and \\(E\\) the number of edges in the unfiltered graph.
Contents
---
# PropertyMap — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.PropertyMap.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.PropertyMap.rst "Download source file")
* .pdf
PropertyMap
===========
Contents
--------
PropertyMap[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#propertymap "Link to this heading")
===========================================================================================================================================
_class_ graph\_tool.PropertyMap(_pmap_, _g_, _key\_type_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "Link to this definition")
Bases: [`object`](https://docs.python.org/3/library/functions.html#object "(in Python v3.13)")
This base class provides a mapping from vertices, edges or whole graphs to arbitrary properties.
See [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-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` | `vector` |
| `vector` | `short` |
| `vector` | `vector` |
| `vector` | `vector`, `vector` |
| `vector` | `vector` |
| `vector` | |
| `vector` | |
| `python::object` | `object` |
Methods
| | |
| --- | --- |
| [`coerce_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.coerce_type "graph_tool.PropertyMap.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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.copy "graph_tool.PropertyMap.copy")
(\[value\_type, full\]) | Return a copy of the property map. |
| [`data_ptr`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.data_ptr "graph_tool.PropertyMap.data_ptr")
() | Return the pointer to memory where the data resides. |
| [`get_2d_array`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_2d_array "graph_tool.PropertyMap.get_2d_array")
(\[pos, dtype\]) | 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, which contains a copy of all entries of the vector-valued property map. |
| [`get_array`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_array "graph_tool.PropertyMap.get_array")
() | Get a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
subclass ([`PropertyArray`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "graph_tool.PropertyArray")
) pointint to the property values. |
| [`get_graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_graph "graph_tool.PropertyMap.get_graph")
() | Get the graph class to which the map refers. |
| [`is_writable`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.is_writable "graph_tool.PropertyMap.is_writable")
() | Return True if the property is writable. |
| [`key_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.key_type "graph_tool.PropertyMap.key_type")
() | Return the key type of the map. |
| [`python_value_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.python_value_type "graph_tool.PropertyMap.python_value_type")
() | Return the python-compatible value type of the map. |
| [`reserve`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.reserve "graph_tool.PropertyMap.reserve")
(size) | Reserve enough space for `size` elements in underlying container. |
| [`resize`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.resize "graph_tool.PropertyMap.resize")
(size) | Resize the underlying container to contain exactly `size` elements. |
| [`set_2d_array`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.set_2d_array "graph_tool.PropertyMap.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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.set_value "graph_tool.PropertyMap.set_value")
(val) | Sets all values in the property map to the same `val`. |
| [`set_values`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.set_values "graph_tool.PropertyMap.set_values")
(vals) | Sets values in the property map to the iterable `vals`. |
| [`shrink_to_fit`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.shrink_to_fit "graph_tool.PropertyMap.shrink_to_fit")
() | Shrink size of underlying container to accommodate only the necessary amount, and thus potentially freeing memory. |
| [`swap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.swap "graph_tool.PropertyMap.swap")
(other) | Swap internal storage with `other`. |
| [`t`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.t "graph_tool.PropertyMap.t")
(f\[, value\_type, no\_array, inplace\]) | Alias to [`transform()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.transform "graph_tool.PropertyMap.transform")
. |
| [`transform`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.transform "graph_tool.PropertyMap.transform")
(f\[, value\_type, no\_array, inplace\]) | Return a copy of the property map with the values transformed by the user-supplied function `f`. |
| [`value_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.value_type "graph_tool.PropertyMap.value_type")
() | Return the value type of the map. |
Attributes
| | |
| --- | --- |
| [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a") | Shortcut to the [`get_array()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_array "graph_tool.PropertyMap.get_array")
method as an attribute. |
| [`fa`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.fa "graph_tool.PropertyMap.fa") | The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, but instead an _indexed_ array is returned, which contains only entries for vertices/edges which are not filtered out. |
| [`ma`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.ma "graph_tool.PropertyMap.ma") | The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, but instead a [`numpy.ma.MaskedArray`](https://numpy.org/doc/stable/reference/maskedarray.baseclass.html#numpy.ma.MaskedArray "(in NumPy v2.3)")
object is returned, which contains only entries for vertices/edges which are not filtered out. |
coerce\_type(_full\=True_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.coerce_type)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.coerce_type "Link to this definition")
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\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.copy)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.copy "Link to this definition")
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\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.data_ptr)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.data_ptr "Link to this definition")
Return the pointer to memory where the data resides.
get\_2d\_array(_pos\=None_, _dtype\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.get_2d_array)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_2d_array "Link to this definition")
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, which 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.
If `pos` is not given (the default), then it will be assumed to correspond to the entire range of the first entry in the map.
The parameter `dtype` determines the desired data-type for the array. If not given, it will be determined automatically (by applying promotion rules when necessary.)
get\_array()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.get_array)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_array "Link to this definition")
Get a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
subclass ([`PropertyArray`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "graph_tool.PropertyArray")
) pointint to 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()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_2d_array "graph_tool.PropertyMap.get_2d_array")
and [`set_2d_array()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.set_2d_array "graph_tool.PropertyMap.set_2d_array")
member functions.
Warning
This function does not copy the data from the property map, and therefore runs in \\(O(1)\\) time.
As a consequence, 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\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.get_graph)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_graph "Link to this definition")
Get the graph class to which the map refers.
is\_writable()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.is_writable)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.is_writable "Link to this definition")
Return True if the property is writable.
key\_type()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.key_type)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.key_type "Link to this definition")
Return the key type of the map. Either ‘g’, ‘v’ or ‘e’.
python\_value\_type()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.python_value_type)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.python_value_type "Link to this definition")
Return the python-compatible value type of the map.
reserve(_size_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.reserve)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.reserve "Link to this definition")
Reserve enough space for `size` elements in underlying container. If the original size is already equal or larger, nothing will happen.
resize(_size_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.resize)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.resize "Link to this definition")
Resize the underlying container to contain exactly `size` elements.
set\_2d\_array(_a_, _pos\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.set_2d_array)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.set_2d_array "Link to this definition")
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\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.set_value)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.set_value "Link to this definition")
Sets all values in the property map to the same `val`.
set\_values(_vals_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.set_values)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.set_values "Link to this definition")
Sets values in the property map to the iterable `vals`.
shrink\_to\_fit()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.shrink_to_fit)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.shrink_to_fit "Link to this definition")
Shrink size of underlying container to accommodate only the necessary amount, and thus potentially freeing memory.
swap(_other_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.swap)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.swap "Link to this definition")
Swap internal storage with `other`.
t(_f_, _value\_type\=None_, _no\_array\=False_, _inplace\=False_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.t "Link to this definition")
Alias to [`transform()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.transform "graph_tool.PropertyMap.transform")
.
transform(_f_, _value\_type\=None_, _no\_array\=False_, _inplace\=False_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.transform)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.transform "Link to this definition")
Return a copy of the property map with the values transformed by the user-supplied function `f`. If given, `value_type` specifies the value type for the new property map.
If the value type of the original map allows, the values will be passed to `f` as a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
, unless no\_array is `True`. Otherwise, they will be passed individually.
If `inplace == True` the transformation happens in-place, without copying the property map. In this case the parameter `value_type` is ignored.
value\_type()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyMap.value_type)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.value_type "Link to this definition")
Return the value type of the map.
a[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "Link to this definition")
Shortcut to the [`get_array()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_array "graph_tool.PropertyMap.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[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.fa "Link to this definition")
The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute.
Warning
Because [advanced indexing](https://numpy.org/doc/stable/user/basics.indexing.html#advanced-indexing "(in NumPy v2.3)")
is triggered, a **copy** of the array is returned, not a view, as is the case for the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute. Nevertheless, the assignment of values to the _whole_ array at once works as expected.
Importantly, this means that this operation runs in time \\(O(N)\\) or O(N + E) for node and edge properties, respectively, where \\(N\\) is the number of vertices and \\(E\\) the number of edges in the unfiltered graph, and therefore can be significantly slower than using the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, which runs in time \\(O(1)\\).
ma[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.ma "Link to this definition")
The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, but instead a [`numpy.ma.MaskedArray`](https://numpy.org/doc/stable/reference/maskedarray.baseclass.html#numpy.ma.MaskedArray "(in NumPy v2.3)")
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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "graph_tool.PropertyArray")
is returned, which is identical to the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute.
Warning
Unlike [`fa`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.fa "graph_tool.PropertyMap.fa")
, the masked array does _not_ copy the property map values.
This function runs in time \\(O(N)\\) or O(N + E) for node and edge properties, respectively, where \\(N\\) is the number of vertices and \\(E\\) the number of edges in the unfiltered graph.
Contents
---
# Quick start guide — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/quickstart.md "Suggest edit")
* [.md](https://graph-tool.skewed.de/static/docs/stable/_sources/quickstart.md "Download source file")
* .pdf
Quick start guide
=================
Contents
--------
Quick start guide[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#quick-start-guide "Link to this heading")
===============================================================================================================================
The [`graph_tool`](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#module-graph_tool "graph_tool")
module provides a [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
class and several algorithms that operate on it. The internals of this class, and of most algorithms, are written in C++ for performance, using the [Boost Graph Library](http://www.boost.org/)
.
The module must be of course imported before it can be used. The package is subdivided into several sub-modules. To import everything from all of them, one can do:
\>>> from graph\_tool.all import \*
In the following, it will always be assumed that the previous line was run.
Creating graphs[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#creating-graphs "Link to this heading")
---------------------------------------------------------------------------------------------------------------------------
An empty graph can be created by instantiating a [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
class:
\>>> g \= Graph()
By default, newly created graphs are always directed. To construct undirected graphs, one must pass a value to the `directed` parameter:
\>>> ug \= Graph(directed\=False)
A graph can always be switched _on-the-fly_ from directed to undirected (and vice versa), with the [`set_directed()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_directed "graph_tool.Graph.set_directed")
method. The “directedness” of the graph can be queried with the [`is_directed()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.is_directed "graph_tool.Graph.is_directed")
method:
\>>> ug \= Graph()
\>>> ug.set\_directed(False)
\>>> assert ug.is\_directed() \== False
Once a graph is created, it can be populated with vertices and edges. A vertex can be added with the [`add_vertex()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_vertex "graph_tool.Graph.add_vertex")
method, which returns an instance of a [`Vertex`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex "graph_tool.Vertex")
class, also called a _vertex descriptor_. For instance, the following code creates two vertices, and returns vertex descriptors stored in the variables `v1` and `v2`.
\>>> v1 \= g.add\_vertex()
\>>> v2 \= g.add\_vertex()
Edges can be added in an analogous manner, by calling the [`add_edge()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_edge "graph_tool.Graph.add_edge")
method, which returns an edge descriptor (an instance of the [`Edge`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#graph_tool.Edge "graph_tool.Edge")
class):
\>>> e \= g.add\_edge(v1, v2)
The above code creates a directed edge from `v1` to `v2`.
A graph can also be created by providing another graph, in which case the entire graph (and its internal property maps, see [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-maps)
) is copied:
\>>> g2 \= Graph(g) \# g2 is a copy of g
Above, `g2` is a “deep” copy of `g`, i.e. any modification of `g2` will not affect `g`.
Note
Graph visualization in `graph-tool` can be interactive! When the `output` parameter of [`graph_draw()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.graph_draw.html#graph_tool.draw.graph_draw "graph_tool.draw.graph_draw")
is omitted, instead of saving to a file, the function opens an interactive window. From there, the user can zoom in or out, rotate the graph, select and move individual nodes or node selections. See [`GraphWidget()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.GraphWidget.html#graph_tool.draw.GraphWidget "graph_tool.draw.GraphWidget")
for documentation on the interactive interface.
If you are using a [Jupyter](https://jupyter.org/)
notebook, the graphs are drawn inline if `output` is omitted. If an interactive window is desired instead, the option `inline = False` should be passed.
We can visualize the graph we created so far with the [`graph_draw()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.graph_draw.html#graph_tool.draw.graph_draw "graph_tool.draw.graph_draw")
function.
\>>> graph\_draw(g, vertex\_text\=g.vertex\_index, output\="two-nodes.svg")
<...>
[](https://graph-tool.skewed.de/static/docs/stable/_images/two-nodes.svg)
A simple directed graph with two vertices and one edge, created by the commands above.[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#id1 "Link to this image")
We can add attributes to the nodes and edges of our graph via [property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-maps)
. For example, suppose we want to add an edge weight and node color to our graph we have first to create two [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
objects as such:
\>>> eweight \= g.new\_ep("double") \# creates an EdgePropertyMap of type double
\>>> vcolor \= g.new\_vp("string") \# creates a VertexPropertyMap of type string
And now we set their values for each vertex and edge:
\>>> eweight\[e\] \= 25.3
\>>> vcolor\[v1\] \= "#1c71d8"
\>>> vcolor\[v2\] \= "#2ec27e"
Property maps can then be used in many `graph-tool` functions to set node and edge properties, for example:
\>>> graph\_draw(g, vertex\_text\=g.vertex\_index, vertex\_fill\_color\=vcolor,
... edge\_pen\_width\=eweight, output\="two-nodes-color.svg")
<...>
[](https://graph-tool.skewed.de/static/docs/stable/_images/two-nodes-color.svg)
The same graph as before, but with edge width and node color specified by property maps.[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#id2 "Link to this image")
Property maps are discussed in more detail in the section [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-maps)
below.
### Adding many edges and vertices at once[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#adding-many-edges-and-vertices-at-once "Link to this heading")
Note
The vertex values passed to the constructor need to be integers per default, but arbitrary objects can be passed as well if the option `hashed = True` is passed. In this case, the mapping of vertex descriptors to vertex ids is obtained via an internal [`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
called `"ids"`. E.g. in the example above we have
\>>> print(g.vp.ids\[0\])
foo
See [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-maps)
below for more details.
It is also possible to add many edges and vertices at once when the graph is created. For example, it is possible to construct graphs directly from a list of edges, e.g.
\>>> g \= Graph(\[('foo', 'bar'), ('gnu', 'gnat')\], hashed\=True)
which is just a convenience shortcut to creating an empty graph and calling [`add_edge_list()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_edge_list "graph_tool.Graph.add_edge_list")
afterward, as we will discuss below.
Edge properties can also be initialized together with the edges by using tuples `(source, target, property_1, property_2, ...)`, e.g.
\>>> g \= Graph(\[('foo', 'bar', .5, 1), ('gnu', 'gnat', .78, 2)\], hashed\=True,
... eprops\=\[('weight', 'double'), ('time', 'int')\])
The `eprops` parameter lists the name and value types of the properties, which are used to create internal property maps with the value encountered (see [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-maps)
below for more details).
It is possible also to pass an adjacency list to construct a graph, which is a dictionary of out-neighbors for every vertex key:
\>>> g \= Graph({0: \[2, 3\], 1: \[4\], 3: \[4, 5\], 6: \[\]})
We can also easily construct graphs from adjacency matrices. They need only to be converted to a sparse scipy matrix (i.e. a subclass of [`scipy.sparse.sparray`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.sparray.html#scipy.sparse.sparray "(in SciPy v1.16.1)")
or [`scipy.sparse.spmatrix`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.spmatrix.html#scipy.sparse.spmatrix "(in SciPy v1.16.1)")
) and passed to the constructor, e.g.:
\>>> m \= np.array(\[\[0, 1, 0\],\
... \[0, 0, 1\],\
... \[0, 1, 0\]\])
\>>> g \= Graph(scipy.sparse.lil\_matrix(m))
The nonzero entries of the matrix are stored as an edge property map named `"weight"` (see [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-maps)
below for more details), e.g.
\>>> m \= np.array(\[\[0, 1.2, 0\],\
... \[0, 0, 10\],\
... \[0, 7, 0\]\])
\>>> g \= Graph(scipy.sparse.lil\_matrix(m))
\>>> print(g.ep.weight.a)
\[ 1.2 7. 10. \]
For undirected graphs (i.e. the option `directed = False` is given) only the upper triangular portion of the passed matrix will be considered, and the remaining entries will be ignored.
We can also add many edges at once `after` the graph has been created using the [`add_edge_list()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_edge_list "graph_tool.Graph.add_edge_list")
method. It accepts any iterable of `(source, target)` pairs, and automatically adds any new vertex seen:
\>>> g.add\_edge\_list(\[(0, 1), (2, 3)\])
Note
As above, if `hashed = True` is passed, the function [`add_edge_list()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_edge_list "graph_tool.Graph.add_edge_list")
returns a [`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
object that maps vertex descriptors to their id values in the list. See [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-maps)
below.
The vertex values passed to [`add_edge_list()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_edge_list "graph_tool.Graph.add_edge_list")
need to be integers per default, but arbitrary objects can be passed as well if the option `hashed = True` is passed, e.g. for string values:
\>>> g.add\_edge\_list(\[('foo', 'bar'), ('gnu', 'gnat')\], hashed\=True,
... hash\_type\="string")
<...>
or for arbitrary (hashable) Python objects:
\>>> g.add\_edge\_list(\[((2, 3), 'foo'), (3, 42.3)\], hashed\=True,
... hash\_type\="object")
<...>
Manipulating graphs[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#manipulating-graphs "Link to this heading")
-----------------------------------------------------------------------------------------------------------------------------------
With vertex and edge descriptors at hand, one can examine and manipulate the graph in an arbitrary manner. For instance, in order to obtain the out-degree of a vertex, we can simply call the [`out_degree()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_degree "graph_tool.Vertex.out_degree")
method:
\>>> g \= Graph()
\>>> v1 \= g.add\_vertex()
\>>> v2 \= g.add\_vertex()
\>>> e \= g.add\_edge(v1, v2)
\>>> print(v1.out\_degree())
1
Note
For undirected graphs, the “out-degree” is synonym for degree, and in this case the in-degree of a vertex is always zero.
Analogously, we could have used the [`in_degree()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_degree "graph_tool.Vertex.in_degree")
method to query the in-degree.
Edge descriptors have two useful methods, [`source()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#graph_tool.Edge.source "graph_tool.Edge.source")
and [`target()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Edge.html#graph_tool.Edge.target "graph_tool.Edge.target")
, which return the source and target vertex of an edge, respectively.
\>>> print(e.source(), e.target())
0 1
We can also directly convert an edge to a tuple of vertices, to the same effect:
\>>> u, v \= e
\>>> print(u, v)
0 1
The [`add_vertex()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_vertex "graph_tool.Graph.add_vertex")
method also accepts an optional parameter which specifies the number of additional vertices to create. If this value is greater than 1, it returns an iterator on the added vertex descriptors:
\>>> vlist \= g.add\_vertex(10)
\>>> print(len(list(vlist)))
10
Each vertex in a graph has a unique index, which is **\*always\*** between \\(0\\) and \\(N-1\\), where \\(N\\) is the number of vertices. This index can be obtained by using the [`vertex_index`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex_index "graph_tool.Graph.vertex_index")
attribute of the graph (which is a _property map_, see [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-maps)
), or by converting the vertex descriptor to an `int`.
\>>> v \= g.add\_vertex()
\>>> print(g.vertex\_index\[v\])
12
\>>> print(int(v))
12
Edges and vertices can also be removed at any time with the [`remove_vertex()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.remove_vertex "graph_tool.Graph.remove_vertex")
and [`remove_edge()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.remove_edge "graph_tool.Graph.remove_edge")
methods,
\>>> g.remove\_edge(e) \# e no longer exists
\>>> g.remove\_vertex(v2) \# the second vertex is also gone
When removing edges, it is important to keep in mind some performance considerations:
Warning
Because of the contiguous indexing, removing a vertex with an index smaller than \\(N-1\\) will **invalidate either the last** (`fast == True`) **or all** (`fast == False`) **descriptors pointing to vertices with higher index**.
As a consequence, if more than one vertex is to be removed at a given time, they should **always** be removed in decreasing index order:
\# 'vs' is a list of
\# vertex descriptors
vs \= sorted(vs)
vs \= reversed(vs)
for v in vs:
g.remove\_vertex(v)
Alternatively (and preferably), a list (or any iterable) may be passed directly as the `vertex` parameter of the [`remove_vertex()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.remove_vertex "graph_tool.Graph.remove_vertex")
function, and the above is performed internally (in C++).
Note that property map values (see [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-maps)
) are unaffected by the index changes due to vertex removal, as they are modified accordingly by the library.
Note
Removing a vertex is typically an \\(O(N)\\) operation. The vertices are internally stored in a [STL vector](http://en.wikipedia.org/wiki/Vector_%28STL%29)
, so removing an element somewhere in the middle of the list requires the shifting of the rest of the list. Thus, fast \\(O(1)\\) removals are only possible if one can guarantee that only vertices in the end of the list are removed (the ones last added to the graph), or if the relative vertex ordering is invalidated. The latter behavior can be achieved by passing the option `fast = True`, to [`remove_vertex()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.remove_vertex "graph_tool.Graph.remove_vertex")
, which causes the vertex being deleted to be ‘swapped’ with the last vertex (i.e. with the largest index), which, in turn, will inherit the index of the vertex being deleted.
Removing an edge is an \\(O(k\_{s} + k\_{t})\\) operation, where \\(k\_{s}\\) is the out-degree of the source vertex, and \\(k\_{t}\\) is the in-degree of the target vertex. This can be made faster by setting [`set_fast_edge_removal()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_removal "graph_tool.Graph.set_fast_edge_removal")
to `True`, in which case it becomes \\(O(1)\\), at the expense of additional data of size \\(O(E)\\).
No edge descriptors are ever invalidated after edge removal, with the exception of the edge itself that is being removed.
Since vertices are uniquely identifiable by their indices, there is no need to keep the vertex descriptor lying around to access them at a later point. If we know its index, we can obtain the descriptor of a vertex with a given index using the [`vertex()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex "graph_tool.Graph.vertex")
method,
\>>> v \= g.vertex(8)
which takes an index, and returns a vertex descriptor. Edges cannot be directly obtained by its index, but if the source and target vertices of a given edge are known, it can be retrieved with the [`edge()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge "graph_tool.Graph.edge")
method
\>>> g.add\_edge(g.vertex(2), g.vertex(3))
<...>
\>>> e \= g.edge(2, 3)
Another way to obtain edge or vertex descriptors is to _iterate_ through them, as described in section [Iterating over vertices and edges](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-iteration)
. This is in fact the most useful way of obtaining vertex and edge descriptors.
Like vertices, edges also have unique indices, which are given by the [`edge_index`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge_index "graph_tool.Graph.edge_index")
property:
\>>> e \= g.add\_edge(g.vertex(0), g.vertex(1))
\>>> print(g.edge\_index\[e\])
1
Differently from vertices, edge indices do not necessarily conform to any specific range. If no edges are ever removed, the indices will be in the range \\(\[0, E-1\]\\), where \\(E\\) is the number of edges, and edges added earlier have lower indices. However if an edge is removed, its index will be “vacant”, and the remaining indices will be left unmodified, and thus will not all lie in the range \\(\[0, E-1\]\\). If a new edge is added, it will reuse old indices, in an increasing order.
### Iterating over vertices and edges[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#iterating-over-vertices-and-edges "Link to this heading")
Algorithms must often iterate through vertices, edges, out-edges of a vertex, etc. The [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
and [`Vertex`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex "graph_tool.Vertex")
classes provide different types of iterators for doing so. The iterators always point to edge or vertex descriptors.
#### Iterating over all vertices or edges[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#iterating-over-all-vertices-or-edges "Link to this heading")
In order to iterate through all the vertices or edges of a graph, the [`vertices()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertices "graph_tool.Graph.vertices")
and [`edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edges "graph_tool.Graph.edges")
methods should be used:
for v in g.vertices():
print(v)
for e in g.edges():
print(e)
The code above will print the vertices and edges of the graph in the order they are found.
#### Iterating over the neighborhood of a vertex[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#iterating-over-the-neighborhood-of-a-vertex "Link to this heading")
Warning
You should never remove vertex or edge descriptors when iterating over them, since this invalidates the iterators. If you plan to remove vertices or edges during iteration, you must first store them somewhere (such as in a list) and remove them only after no iterator is being used. Removal during iteration will cause bad things to happen.
The out- and in-edges of a vertex, as well as the out- and in-neighbors can be iterated through with the [`out_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_edges "graph_tool.Vertex.out_edges")
, [`in_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_edges "graph_tool.Vertex.in_edges")
, [`out_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_neighbors "graph_tool.Vertex.out_neighbors")
and [`in_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_neighbors "graph_tool.Vertex.in_neighbors")
methods, respectively.
for v in g.vertices():
for e in v.out\_edges():
print(e)
for w in v.out\_neighbors():
print(w)
\# the edge and neighbors order always match
for e, w in zip(v.out\_edges(), v.out\_neighbors()):
assert e.target() \== w
The code above will print the out-edges and out-neighbors of all vertices in the graph.
Example analysis: an online social network[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#example-analysis-an-online-social-network "Link to this heading")
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Let us consider an online social network of [facebook users](https://networks.skewed.de/net/ego_social)
, available from the [Netzschleuder network repository](http://networks.skewed.de/)
. We can load it in `graph-tool` via the [`graph_tool.collection.ns`](https://graph-tool.skewed.de/static/docs/stable/collection.html#graph_tool.collection.ns "graph_tool.collection.ns")
interface:
\>>> g \= collection.ns\["ego\_social/facebook\_combined"\]
We can quickly inspect the structure of the network by visualizing it:
\>>> graph\_draw(g, g.vp.\_pos, output\="facebook.pdf")
<...>
[](https://graph-tool.skewed.de/static/docs/stable/_images/facebook.png)
Network of friendships among users on Facebook.[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#id3 "Link to this image")
Note
A SBM provides a statistically principled method to cluster the nodes of a network according to their latent mixing patterns. `graph-tool` provides extensive support for this kind of analysis, as detailed in a [dedicated HOWTO](https://graph-tool.skewed.de/static/docs/stable/demos/inference/inference.html#inference-howto)
.
This methodology overcomes some serious limitations of outdated approaches, such as modularity maximization, which should in general [be avoided](https://skewed.de/tiago/blog/modularity-harmful)
.
This network seems to be composed of many communities with homophilic patterns. We can identify them reliably by inferring a `stochastic block model` (SBM), achieved by calling [`minimize_blockmodel_dl()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.minimize_blockmodel_dl.html#graph_tool.inference.minimize_blockmodel_dl "graph_tool.inference.minimize_blockmodel_dl")
:
\>>> state \= minimize\_blockmodel\_dl(g)
This returns a [`BlockState`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.inference.BlockState.html#graph_tool.inference.BlockState "graph_tool.inference.BlockState")
object. We can visualize the results with:
\>>> state.draw(pos\=g.vp.\_pos, output\="facebook-sbm.pdf")
<...>
[](https://graph-tool.skewed.de/static/docs/stable/_images/facebook-sbm.png)
Groups of nodes identified by fitting a SBM to the facebook frendship data.[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#id4 "Link to this image")
Note
The algorithm to compute betweenness centrality has a quadratic complexity on the number of nodes of the network, so it can become slow as it becomes large. However in `graph-tool` it is implemented in parallel, affording us more performance. For the network being considered, it finishes in under a second with a modern laptop.
We might want to identify the nodes and edges that act as “bridges” between these communities. We can do so by computing the [betweenness centrality](https://en.wikipedia.org/wiki/Betweenness_centrality)
, obtained via [`betweenness()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.betweenness.html#graph_tool.centrality.betweenness "graph_tool.centrality.betweenness")
:
\>>> vb, eb \= betweenness(g)
This returns an vertex and edge property map with the respective betweenness values. We can visualize them with:
Tip
The function [`prop_to_size()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.prop_to_size.html#graph_tool.draw.prop_to_size "graph_tool.draw.prop_to_size")
provides a convenient way to transformation the property map values to ranges more appropriate for sizes in [`graph_draw()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.draw.graph_draw.html#graph_tool.draw.graph_draw "graph_tool.draw.graph_draw")
. See also [Transformations](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-trans)
.
\>>> graph\_draw(g, g.vp.\_pos, vertex\_fill\_color\=prop\_to\_size(vb, 0, 1, power\=.1),
... vertex\_size\=prop\_to\_size(vb, 3, 12, power\=.2), vorder\=vb,
... output\="facebook-bt.pdf")
<...>
[](https://graph-tool.skewed.de/static/docs/stable/_images/facebook-bt.png)
The node betweeness values correspond to the color and size of the nodes.[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#id5 "Link to this image")
Property maps[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#property-maps "Link to this heading")
-----------------------------------------------------------------------------------------------------------------------
Property maps are a way of associating additional information to the vertices, edges, or to the graph itself. There are thus three types of property maps: vertex, edge, and graph. They are handled by the classes [`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
, [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
, and [`GraphPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap "graph_tool.GraphPropertyMap")
. Each created property map has an associated _value type_, which must be chosen from the predefined set:
| | |
| --- | --- |Value types for property maps[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#id6 "Link to this table")
| Type name | Alias |
| --- | --- |
| `bool` | `uint8_t` |
| `int16_t` | `short` |
| `int32_t` | `int` |
| `int64_t` | `long`, `long long` |
| `double` | `float` |
| `long double` | |
| `string` | |
| `vector` | `vector` |
| `vector` | `vector` |
| `vector` | `vector` |
| `vector` | `vector`, `vector` |
| `vector` | `vector` |
| `vector` | |
| `vector` | |
| `python::object` | `object` |
New property maps can be created for a given graph by calling one of the methods [`new_vertex_property()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_vertex_property "graph_tool.Graph.new_vertex_property")
(alias [`new_vp()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_vp "graph_tool.Graph.new_vp")
), [`new_edge_property()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_edge_property "graph_tool.Graph.new_edge_property")
(alias [`new_ep()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_ep "graph_tool.Graph.new_ep")
), or [`new_graph_property()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_graph_property "graph_tool.Graph.new_graph_property")
(alias [`new_gp()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_gp "graph_tool.Graph.new_gp")
), for each map type. The values are then accessed by vertex or edge descriptors, or the graph itself, as such:
from numpy.random import randint
g \= Graph()
g.add\_vertex(100)
\# insert some random links
for s, t in zip(randint(0, 100, 100), randint(0, 100, 100)):
g.add\_edge(g.vertex(s), g.vertex(t))
vprop \= g.new\_vertex\_property("double") \# Double-precision floating point
v \= g.vertex(10)
vprop\[v\] \= 3.1416
vprop2 \= g.new\_vertex\_property("vector") \# Vector of ints
v \= g.vertex(40)
vprop2\[v\] \= \[1, 3, 42, 54\]
eprop \= g.new\_edge\_property("object") \# Arbitrary Python object.
e \= g.edges().next()
eprop\[e\] \= {"foo": "bar", "gnu": 42} \# In this case, a dict.
gprop \= g.new\_graph\_property("bool") \# Boolean
gprop\[g\] \= True
It is possible also to access vertex property maps directly by vertex indices:
\>>> print(vprop\[10\])
3.1416
Warning
The following lines are equivalent:
eprop\[(30, 40)\]
eprop\[g.edge(30, 40)\]
Which means that indexing via (source, target) pairs is slower than via edge descriptors, since the function [`edge()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge "graph_tool.Graph.edge")
needs to be called first.
And likewise we can access edge descriptors via (source, target) pairs:
\>>> g.add\_edge(30, 40)
<...>
\>>> eprop\[(30, 40)\] \= "gnat"
We can also iterate through the property map values directly, i.e.
\>>> print(list(vprop)\[:10\])
\[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0\]
Property maps with scalar value types can also be accessed as a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
, with the [`get_array()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_array "graph_tool.PropertyMap.get_array")
method, or the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, e.g.,
from numpy.random import random
\# this assigns random values to the vertex properties
vprop.get\_array()\[:\] = random(g.num\_vertices())
\# or more conveniently (this is equivalent to the above)
vprop.a = random(g.num\_vertices())
Array interface for filtered graphs
For filtered graphs (see [Graph filtering](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-graph-filtering)
below), it’s possible to get arrays that only point to the nodes and edges that are not filtered out via the [`fa`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.fa "graph_tool.PropertyMap.fa")
and [`ma`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.ma "graph_tool.PropertyMap.ma")
attributes instead.
### Transformations[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#transformations "Link to this heading")
We usually want to apply transformations to the values of property maps. This can be achieved via iteration (see [Iterating over vertices and edges](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-iteration)
), but since this is a such a common operation, there’s a more convenient way to do this via the [`transform()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.transform "graph_tool.PropertyMap.transform")
method (or is shorter alias [`t()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.t "graph_tool.PropertyMap.t")
), which takes a function and returns a copy of the property map with the function applied to its values:
from numpy import abs
from numpy.random import random
\# Vertex property map with random values in the range \[-.5, .5\]
rand = g.new\_vp("double", vals=random(g.num\_vertices()) - .5)
\# The following returns a copy of \`rand\` but containing only the absolute values
m = rand.t(abs)
Tip
Transformations are particularly useful to pass temporary properties to functions, e.g.
erand = g.new\_ep("double", vals=random(g.num\_edges()) - .5)
pos = sfdp\_layout(g, eweight=erand.t(abs))
### Internal property maps[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#internal-property-maps "Link to this heading")
Any created property map can be made “internal” to the corresponding graph. This means that it will be copied and saved to a file together with the graph. Properties are internalized by including them in the graph’s dictionary-like attributes [`vertex_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex_properties "graph_tool.Graph.vertex_properties")
, [`edge_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge_properties "graph_tool.Graph.edge_properties")
or [`graph_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.graph_properties "graph_tool.Graph.graph_properties")
(or their aliases, [`vp`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vp "graph_tool.Graph.vp")
, [`ep`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.ep "graph_tool.Graph.ep")
or [`gp`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.gp "graph_tool.Graph.gp")
, respectively). When inserted in the graph, the property maps must have an unique name (between those of the same type):
\>>> eprop \= g.new\_edge\_property("string")
\>>> g.ep\["some name"\] \= eprop
\>>> g.list\_properties()
some name (edge) (type: string)
Internal graph property maps behave slightly differently. Instead of returning the property map object, the value itself is returned from the dictionaries:
\>>> gprop \= g.new\_graph\_property("int")
\>>> g.gp\["foo"\] \= gprop \# this sets the actual property map
\>>> g.gp\["foo"\] \= 42 \# this sets its value
\>>> print(g.gp\["foo"\])
42
\>>> del g.gp\["foo"\] \# the property map entry is deleted from the dictionary
For convenience, the internal property maps can also be accessed via attributes:
\>>> vprop \= g.new\_vertex\_property("double")
\>>> g.vp.foo \= vprop \# equivalent to g.vp\["foo"\] = vprop
\>>> v \= g.vertex(0)
\>>> g.vp.foo\[v\] \= 3.14
\>>> print(g.vp.foo\[v\])
3.14
Graph I/O[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#graph-i-o "Link to this heading")
---------------------------------------------------------------------------------------------------------------
Graphs can be saved and loaded in four formats: [graphml](http://graphml.graphdrawing.org/)
, [dot](http://www.graphviz.org/doc/info/lang.html)
, [gml](http://www.fim.uni-passau.de/en/fim/faculty/chairs/theoretische-informatik/projects.html)
and a custom binary format `gt` (see [The gt file format](https://graph-tool.skewed.de/static/docs/stable/gt_format.html#sec-gt-format)
).
Warning
The binary format `gt` and the text-based `graphml` are the preferred formats, since they are by far the most complete. Both these formats are equally complete, but the `gt` format is faster and requires less storage.
The `dot` and `gml` formats are fully supported, but since they contain no precise type information, all properties are read as strings (or also as double, in the case of `gml`), and must be converted by hand to the desired type. Therefore you should always use either `gt` or `graphml`, since they implement an exact bit-for-bit representation of all supported [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-maps)
types, except when interfacing with other software, or existing data, which uses `dot` or `gml`.
Note
Graph classes can also be pickled with the [`pickle`](https://docs.python.org/3/library/pickle.html#module-pickle "(in Python v3.13)")
module.
A graph can be saved or loaded to a file with the [`save`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.save "graph_tool.Graph.save")
and [`load`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.load "graph_tool.Graph.load")
methods, which take either a file name or a file-like object. A graph can also be loaded from disc with the [`load_graph()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.load_graph.html#graph_tool.load_graph "graph_tool.load_graph")
function, as such:
g \= Graph()
\# ... fill the graph ...
g.save("my\_graph.gt.gz")
g2 \= load\_graph("my\_graph.gt.gz")
\# g and g2 should be identical copies of each other
Graph filtering[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#graph-filtering "Link to this heading")
---------------------------------------------------------------------------------------------------------------------------
Note
It is important to emphasize that the filtering functionality does not add any performance overhead when the graph is not being filtered. In this case, the algorithms run just as fast as if the filtering functionality didn’t exist.
One of the unique features of `graph-tool` is the “on-the-fly” filtering of edges and/or vertices. Filtering means the temporary masking of vertices/edges, which are in fact not really removed, and can be easily recovered.
Ther are two different ways to enable graph filtering: via graph views or inplace filtering, which are covered in the following.
### Graph views[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#graph-views "Link to this heading")
It is often desired to work with filtered and unfiltered graphs simultaneously, or to temporarily create a filtered version of graph for some specific task. For these purposes, `graph-tool` provides a [`GraphView`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView "graph_tool.GraphView")
class, which represents a filtered “view” of a graph, and behaves as an independent graph object, which shares the underlying data with the original graph. Graph views are constructed by instantiating a [`GraphView`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView "graph_tool.GraphView")
class, and passing a graph object which is supposed to be filtered, together with the desired filter parameters. For example, to create a directed view of an undirected graph `g` above, one could do:
\>>> ug \= GraphView(g, directed\=True)
\>>> ug.is\_directed()
True
Graph views also provide a direct and convenient approach to vertex/edge filtering. Let us consider the facebook friendship graph we used before and the betweeness centrality values:
\>>> g \= collection.ns\["ego\_social/facebook\_combined"\]
\>>> vb, eb \= betweenness(g)
Let us suppose we would like to see how the graph would look like if some of the edges with higher betweeness values were removed. We can do this by a [`GraphView`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView "graph_tool.GraphView")
object and passing the `efilt` paramter:
\>>> u \= GraphView(g, efilt\=eb.fa < 1e-6)
Note
[`GraphView`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView "graph_tool.GraphView")
objects behave _exactly_ like regular [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
objects. In fact, [`GraphView`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView "graph_tool.GraphView")
is a subclass of [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
. The only difference is that a [`GraphView`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView "graph_tool.GraphView")
object shares its internal data with its parent [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
class. Therefore, if the original [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
object is modified, this modification will be reflected immediately in the [`GraphView`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView "graph_tool.GraphView")
object, and vice versa.
Since [`GraphView`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView "graph_tool.GraphView")
is a derived class from [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
, and its instances are accepted as regular graphs by every function of the library. Graph views are “first class citizens” in `graph-tool`.
If we visualize the graph we can see it now has been broken up in many components:
\>>> graph\_draw(u, pos\=g.vp.\_pos, output\="facebook-filtered.pdf")
<...>
[](https://graph-tool.skewed.de/static/docs/stable/_images/facebook-filtered.png)
Facebook friendship network with edges with a betweeness centrality value above \\(10^{-6}\\) filtered out.[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#id7 "Link to this image")
Note however that no copy of the original graph was done, and no edge has been in fact removed. If we inspect the original graph `g` in the example above, it will be intact.
In the example above, we passed a boolean array as the `efilt`, but we could have passed also a boolean property map, a function that takes an edge as single parameter, and returns `True` if the edge should be kept and `False` otherwise. For instance, the above could be equivalently achieved as:
\>>> u \= GraphView(g, efilt\=lambda e: eb\[e\] < 1e-6)
But note however that would be slower, since it would involve one function call per edge in the graph.
Vertices can also be filtered in an entirerly analogous fashion using the `vfilt` paramter.
#### Composing graph views[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#composing-graph-views "Link to this heading")
Since graph views behave like regular graphs, one can just as easily create graph views `of graph views`. This provides a convenient way of composing filters. For instance, suppose we wanto to isolate the minimum spanning tree of all vertices of agraph above which have a degree larger than four:
\>>> g, pos \= triangulation(random((500, 2)) \* 4, type\="delaunay")
\>>> u \= GraphView(g, vfilt\=lambda v: v.out\_degree() \> 4)
\>>> tree \= min\_spanning\_tree(u)
\>>> u \= GraphView(u, efilt\=tree)
The resulting graph view can be used and visualized as normal:
\>>> bv, be \= betweenness(u)
\>>> be.a /= be.a.max() / 5
\>>> graph\_draw(u, pos\=pos, vertex\_fill\_color\=bv,
... edge\_pen\_width\=be, output\="mst-view.svg")
<...>

A composed view, obtained as the minimum spanning tree of all vertices in the graph which have a degree larger than four. The edge thickness indicates the betweeness values, as well as the node colors.[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#id8 "Link to this image")
### In-place graph filtering[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#in-place-graph-filtering "Link to this heading")
It is possible also to filter graphs “in-place”, i.e. without creating an additional object. To achieve this, vertices or edges which are to be filtered should be marked with a [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
with value type `bool`, and then set with [`set_vertex_filter()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_vertex_filter "graph_tool.Graph.set_vertex_filter")
or [`set_edge_filter()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_edge_filter "graph_tool.Graph.set_edge_filter")
methods. Vertex or edges with value “1” are `kept` in the graphs, and those with value “0” are filtered out. All manipulation functions and algorithms will work as if the marked edges or vertices were removed from the graph, with minimum overhead.
For example, to reproduce the same example as before for the facebook graph we could have done:
\>>> g \= collection.ns\["ego\_social/facebook\_combined"\]
\>>> vb, eb \= betweenness(g)
\>>> mask \= g.new\_ep("bool", vals \= eb.fa < 1e-5)
\>>> g.set\_edge\_filter(mask)
The `mask` property map has a bool type, with value `1` if the edge belongs to the tree, and `0` otherwise.
Everything should work transparently on the filtered graph, simply as if the masked edges were removed.
The original graph can be recovered by setting the edge filter to `None`.
g.set\_edge\_filter(None)
Everything works in analogous fashion with vertex filtering.
Additionally, the graph can also have its edges reversed with the [`set_reversed()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_reversed "graph_tool.Graph.set_reversed")
method. This is also an \\(O(1)\\) operation, which does not really modify the graph.
As mentioned previously, the directedness of the graph can also be changed “on-the-fly” with the [`set_directed()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_directed "graph_tool.Graph.set_directed")
method.
Advanced iteration[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#advanced-iteration "Link to this heading")
---------------------------------------------------------------------------------------------------------------------------------
### Faster iteration over vertices and edges without descriptors[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#faster-iteration-over-vertices-and-edges-without-descriptors "Link to this heading")
The mode of iteration considered [above](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-iteration)
is convenient, but requires the creation of vertex and edge descriptor objects, which incurs a performance overhead. A faster approach involves the use of the methods [`iter_vertices()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_vertices "graph_tool.Graph.iter_vertices")
, [`iter_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_edges "graph_tool.Graph.iter_edges")
, [`iter_out_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_out_edges "graph_tool.Graph.iter_out_edges")
, [`iter_in_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_in_edges "graph_tool.Graph.iter_in_edges")
, [`iter_all_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_all_edges "graph_tool.Graph.iter_all_edges")
, [`iter_out_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_out_neighbors "graph_tool.Graph.iter_out_neighbors")
, [`iter_in_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_in_neighbors "graph_tool.Graph.iter_in_neighbors")
, [`iter_all_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_all_neighbors "graph_tool.Graph.iter_all_neighbors")
, which return vertex indices and pairs thereof, instead of descriptors objects, to specify vertex and edges, respectively.
For example, for the graph:
g \= Graph(\[(0, 1), (2, 3), (2, 4)\])
we have
for v in g.iter\_vertices():
print(v)
for e in g.iter\_edges():
print(e)
which yields
0
1
2
3
4
\[0, 1\]
\[2, 3\]
\[2, 4\]
and likewise for the iteration over the neighborhood of a vertex:
for v in g.iter\_vertices():
for e in g.iter\_out\_edges(v):
print(e)
for w in g.iter\_out\_neighbors(v):
print(w)
### Even faster, “loopless” iteration over vertices and edges using arrays[#](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#even-faster-loopless-iteration-over-vertices-and-edges-using-arrays "Link to this heading")
While more convenient, looping over the graph as described in the previous sections are not quite the most efficient approaches to operate on graphs. This is because the loops are performed in pure Python, thus undermining the main feature of the library, which is the offloading of loops from Python to C++. Following the [`numpy`](https://numpy.org/doc/stable/reference/index.html#module-numpy "(in NumPy v2.3)")
philosophy, [`graph_tool`](https://graph-tool.skewed.de/static/docs/stable/graph_tool.html#module-graph_tool "graph_tool")
also provides an array-based interface that avoids loops in Python. This is done with the [`get_vertices()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_vertices "graph_tool.Graph.get_vertices")
, [`get_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_edges "graph_tool.Graph.get_edges")
, [`get_out_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_out_edges "graph_tool.Graph.get_out_edges")
, [`get_in_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_in_edges "graph_tool.Graph.get_in_edges")
, [`get_all_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_all_edges "graph_tool.Graph.get_all_edges")
, [`get_out_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_out_neighbors "graph_tool.Graph.get_out_neighbors")
, [`get_in_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_in_neighbors "graph_tool.Graph.get_in_neighbors")
, [`get_all_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_all_neighbors "graph_tool.Graph.get_all_neighbors")
, [`get_out_degrees()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_out_degrees "graph_tool.Graph.get_out_degrees")
, [`get_in_degrees()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_in_degrees "graph_tool.Graph.get_in_degrees")
and [`get_total_degrees()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_total_degrees "graph_tool.Graph.get_total_degrees")
methods, which return [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
instances instead of iterators.
For example, using this interface we can get the out-degree of each node via:
print(g.get\_out\_degrees(g.get\_vertices()))
\[1 0 2 0 0\]
or the sum of the product of the in and out-degrees of the endpoints of each edge with:
edges \= g.get\_edges()
in\_degs \= g.get\_in\_degrees(g.get\_vertices())
out\_degs \= g.get\_out\_degrees(g.get\_vertices())
print((out\_degs\[edges\[:,0\]\] \* in\_degs\[edges\[:,1\]\]).sum())
5
Contents
---
# Graph — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.Graph.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.Graph.rst "Download source file")
* .pdf
Graph
=====
Contents
--------
Graph[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph "Link to this heading")
=========================================================================================================================
_class_ graph\_tool.Graph(_g\=None_, _directed\=True_, _prune\=False_, _vorder\=None_, _fast\_edge\_removal\=False_, _fast\_edge\_lookup\=False_, _\*\*kwargs_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "Link to this definition")
General multigraph class.
This class encapsulates either a directed multigraph (default or if `directed == True`) or an undirected multigraph (if `directed == False`), with optional internal edge, vertex or graph properties.
If `g` is specified, it can be one of:
> 1. Another [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
> object, in which case the corresponding graph (and its internal properties) will be copied.
>
> 2. An integer, in which case it corresponds to the number of vertices in the graph, which is initially empty.
>
> 3. An edge list, i.e. an iterable over (source, target) pairs, which will be used to populate the graph.
>
> This is equivalent to calling [`add_edge_list()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_edge_list "graph_tool.Graph.add_edge_list")
> with an empty graph, as follows:
>
> \>>> elist \= \[(0, 1), (0, 2)\]
> \>>> g \= gt.Graph()
> \>>> g.add\_edge\_list(elist)
>
> 4. An adjacency list, i.e. a dictionary with vertex keys mapping to an interable of vertices, which will be used to populate the graph. For directed graphs, the adjacency should list the out-neighbors.
>
> This is equivalent to calling [`add_edge_list()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_edge_list "graph_tool.Graph.add_edge_list")
> as such:
>
> \>>> adj \= {0: \[1, 2\], 2: \[3\], 4: \[\]}
> \>>> def elist():
> ... for u, vw in adj.items():
> ... k \= 0
> ... for v in vw:
> ... k += 1
> ... yield u, v
> ... if k \== 0:
> ... yield u, None
> \>>> g \= gt.Graph()
> \>>> g.add\_edge\_list(elist())
>
> Note
>
> For undirected graphs, if a vertex `u` appears in the adjacency list of `v` and vice versa, then the edge `(u,v)` is added twice in the graph. To prevent this from happening the adjancecy list should mention an edge only once.
>
> 5. A sparse adjacency matrix of type [`scipy.sparse.sparray`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.sparray.html#scipy.sparse.sparray "(in SciPy v1.16.1)")
> or [`scipy.sparse.spmatrix`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.spmatrix.html#scipy.sparse.spmatrix "(in SciPy v1.16.1)")
> . The matrix entries will be stored as an internal [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
> named `"weight"`. If `directed == False`, only the upper triangular portion of this matrix will be considered, and the remaining entries will be ignored.
>
> This is equivalent to calling [`add_edge_list()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_edge_list "graph_tool.Graph.add_edge_list")
> as such:
>
> \>>> a \= scipy.sparse.coo\_array(\[\[0, 2, 1\], \[3, 1, 2\], \[0, 1, 0\]\])
> \>>> s, t, w \= scipy.sparse.find(a)
> \>>> es \= np.array(\[s, t, w\]).T
> \>>> g \= gt.Graph(a.shape\[0\])
> \>>> g.add\_edge\_list(es, eprops\=\[("weight", "int")\])
>
In cases 3 and 4 above, all remaining keyword parameters passed to [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
will be passed along to the [`Graph.add_edge_list()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_edge_list "graph_tool.Graph.add_edge_list")
function. If the option `hashed == True` is passed, the vertex ids will be stored in an internal [`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
called `"ids"`.
In case `g` is specified and points to a [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
object, the following options take effect:
* If `prune` is set to `True`, only the filtered graph will be copied, and the new graph object will not be filtered. Optionally, a tuple of three booleans can be passed as value to `prune`, to specify a different behavior to vertex, edge, and reversal filters, respectively.
* If `vorder` is specified, it should correspond to a vertex [`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
specifying the ordering of the vertices in the copied graph.
The value of `fast_edge_removal` is passed to [`set_fast_edge_removal()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_removal "graph_tool.Graph.set_fast_edge_removal")
.
The value of `fast_edge_lookup` is passed to [`set_fast_edge_lookup()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_lookup "graph_tool.Graph.set_fast_edge_lookup")
.
Note
The graph is implemented internally as an [adjacency list](http://en.wikipedia.org/wiki/Adjacency_list)
, where both vertex and edge lists are C++ STL vectors.
copy()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.copy)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.copy "Link to this definition")
Return a deep copy of self. All [internal property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-internal-props)
are also copied.
Iterating over vertices and edges
See [Iterating over vertices and edges](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-iteration)
for more documentation and examples.
Iterator-based interface with descriptors:
vertices()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.vertices)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertices "Link to this definition")
Return an [`iterator`](https://docs.python.org/3/library/stdtypes.html#iterator.__iter__ "(in Python v3.13)")
over the vertices.
Note
The order of the vertices traversed by the iterator **always** corresponds to the vertex index ordering, as given by the [`vertex_index`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex_index "graph_tool.Graph.vertex_index")
property map.
Examples
\>>> g \= gt.Graph()
\>>> vlist \= list(g.add\_vertex(5))
\>>> vlist2 \= \[\]
\>>> for v in g.vertices():
... vlist2.append(v)
...
\>>> assert(vlist \== vlist2)
edges()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.edges)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edges "Link to this definition")
Return an [`iterator`](https://docs.python.org/3/library/stdtypes.html#iterator.__iter__ "(in Python v3.13)")
over the edges.
Note
The order of the edges traversed by the iterator **does not** necessarily correspond to the edge index ordering, as given by the [`edge_index`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge_index "graph_tool.Graph.edge_index")
property map. This will only happen after [`reindex_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.reindex_edges "graph_tool.Graph.reindex_edges")
is called, or in certain situations such as just after a graph is loaded from a file. However, further manipulation of the graph may destroy the ordering.
Iterator-based interface without descriptors:
iter\_vertices(_vprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.iter_vertices)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_vertices "Link to this definition")
Return an iterator over the vertex indices, and optional vertex properties list `vprops`.
Note
This mode of iteration is more efficient than using [`vertices()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertices "graph_tool.Graph.vertices")
, as descriptor objects are not created.
Examples
\>>> g \= gt.Graph()
\>>> g.add\_vertex(5)
<...>
\>>> for v in g.iter\_vertices():
... print(v)
0
1
2
3
4
iter\_edges(_eprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.iter_edges)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_edges "Link to this definition")
Return an iterator over the edge `` `(source, target) `` pairs, and optional edge properties list `eprops`.
Note
This mode of iteration is more efficient than using [`edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edges "graph_tool.Graph.edges")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["karate"\]
\>>> for s, t, i in g.iter\_edges(\[g.edge\_index\]):
... print(s, t, i)
... if s \== 5:
... break
1 0 0
2 0 1
2 1 2
3 0 3
3 1 4
3 2 5
4 0 6
5 0 7
iter\_out\_edges(_v_, _eprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.iter_out_edges)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_out_edges "Link to this definition")
Return an iterator over the out-edge `` `(source, target) `` pairs for vertex `v`, and optional edge properties list `eprops`.
Note
This mode of iteration is more efficient than using [`out_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_edges "graph_tool.Vertex.out_edges")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for s, t, i in g.iter\_out\_edges(66, \[g.edge\_index\]):
... print(s, t, i)
66 63 5266
66 20369 5267
66 13980 5268
66 8687 5269
66 38674 5270
iter\_in\_edges(_v_, _eprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.iter_in_edges)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_in_edges "Link to this definition")
Return an iterator over the in-edge `` `(source, target) `` pairs for vertex `v`, and optional edge properties list `eprops`.
Note
This mode of iteration is more efficient than using [`in_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_edges "graph_tool.Vertex.in_edges")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for s, t, i in g.iter\_in\_edges(66, \[g.edge\_index\]):
... print(s, t, i)
8687 66 179681
20369 66 255033
38674 66 300230
iter\_all\_edges(_v_, _eprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.iter_all_edges)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_all_edges "Link to this definition")
Return an iterator over the in- and out-edge `` `(source, target) `` pairs for vertex `v`, and optional edge properties list `eprops`.
Note
This mode of iteration is more efficient than using [`all_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.all_edges "graph_tool.Vertex.all_edges")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for s, t, i in g.iter\_all\_edges(66, \[g.edge\_index\]):
... print(s, t, i)
66 63 5266
66 20369 5267
66 13980 5268
66 8687 5269
66 38674 5270
8687 66 179681
20369 66 255033
38674 66 300230
iter\_out\_neighbors(_v_, _vprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.iter_out_neighbors)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_out_neighbors "Link to this definition")
Return an iterator over the out-neighbors of vertex `v`, and optional vertex properties list `vprops`.
Note
This mode of iteration is more efficient than using [`out_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_neighbors "graph_tool.Vertex.out_neighbors")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for u, i in g.iter\_out\_neighbors(66, \[g.vp.uid\]):
... print(u, i)
63 \['paul wilders '\]
20369 \['Zhen-Xjell '\]
13980 \['Hooman '\]
8687 \['H. Loeung (howe81) ', 'howe81 ', 'Howie L (howe81) '\]
38674 \['Howie L (howe81) '\]
iter\_in\_neighbors(_v_, _vprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.iter_in_neighbors)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_in_neighbors "Link to this definition")
Return an iterator over the in-neighbors of vertex `v`, and optional vertex properties list `vprops`.
Note
This mode of iteration is more efficient than using [`in_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_neighbors "graph_tool.Vertex.in_neighbors")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for u, i in g.iter\_in\_neighbors(66, \[g.vp.uid\]):
... print(u, i)
8687 \['H. Loeung (howe81) ', 'howe81 ', 'Howie L (howe81) '\]
20369 \['Zhen-Xjell '\]
38674 \['Howie L (howe81) '\]
iter\_all\_neighbors(_v_, _vprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.iter_all_neighbors)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_all_neighbors "Link to this definition")
Return an iterator over the in- and out-neighbors of vertex `v`, and optional vertex properties list `vprops`.
Note
This mode of iteration is more efficient than using [`all_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.all_neighbors "graph_tool.Vertex.all_neighbors")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for u, i in g.iter\_all\_neighbors(66, \[g.vp.uid\]):
... print(u, i)
63 \['paul wilders '\]
20369 \['Zhen-Xjell '\]
13980 \['Hooman '\]
8687 \['H. Loeung (howe81) ', 'howe81 ', 'Howie L (howe81) '\]
38674 \['Howie L (howe81) '\]
8687 \['H. Loeung (howe81) ', 'howe81 ', 'Howie L (howe81) '\]
20369 \['Zhen-Xjell '\]
38674 \['Howie L (howe81) '\]
iter\_edge\_range(_s_, _t_, _eprops_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.iter_edge_range)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.iter_edge_range "Link to this definition")
Return an iterator over the edge properties list `eprops` for parallel edges between vertices `s` and `t`.
This operation normally will take \\(O(\\times\\min(k(s), k(t)))\\) time, where \\(k(s)\\) and \\(k(t)\\) are the out-degree and in-degree (or out-degree if undirected) of vertices \\(s\\) and \\(t\\). However, if [`set_fast_edge_lookup()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_lookup "graph_tool.Graph.set_fast_edge_lookup")
is set to True, this operation becomes \\(O(m)\\), where \\(m\\) being the number of parallel edges.
Note
This mode of iteration is more efficient than using [`edge()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge "graph_tool.Graph.edge")
, as descriptor objects are not created.
Examples
\>>> g \= gt.Graph(\[(0, 1), (0, 1)\])
\>>> for i in g.iter\_edge\_range(0, 1, \[g.edge\_index\]):
... print(i)
\[0\]
\[1\]
Array-based interface:
get\_vertices(_vprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_vertices)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_vertices "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the vertex indices, and optional vertex properties list `vprops`. If `vprops` is not empty, the shape of the array will be `(V, 1 + len(vprops))`, where `V` is the number of vertices, and each line will contain the vertex and the vertex property values.
Note
The order of the vertices is identical to [`vertices()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertices "graph_tool.Graph.vertices")
.
Examples
\>>> g \= gt.Graph()
\>>> g.add\_vertex(5)
<...>
\>>> g.get\_vertices()
array(\[0, 1, 2, 3, 4\])
get\_edges(_eprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_edges)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_edges "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the edges, and optional edge properties list `eprops`. The shape of the array will be `(E, 2 + len(eprops))`, where `E` is the number of edges, and each line will contain the source, target and the edge property values.
Note
The order of the edges is identical to [`edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edges "graph_tool.Graph.edges")
.
Examples
\>>> g \= gt.random\_graph(6, lambda: 1, directed\=False)
\>>> g.get\_edges(\[g.edge\_index\])
array(\[\[3, 2, 0\],\
\[4, 1, 2\],\
\[5, 0, 1\]\])
get\_out\_edges(_v_, _eprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_out_edges)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_out_edges "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the out-edges of vertex `v`, and optional edge properties list `eprops`. The shape of the array will be `(E, 2 + len(eprops))`, where `E` is the number of edges, and each line will contain the source, target and the edge property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_out\_edges(66, \[g.edge\_index\])
array(\[\[ 66, 63, 5266\],\
\[ 66, 20369, 5267\],\
\[ 66, 13980, 5268\],\
\[ 66, 8687, 5269\],\
\[ 66, 38674, 5270\]\])
get\_in\_edges(_v_, _eprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_in_edges)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_in_edges "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-edges of vertex `v`, and optional edge properties list `eprops`. The shape of the array will be `(E, 2 + len(eprops))`, where `E` is the number of edges, and each line will contain the source, target and the edge property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_in\_edges(66, \[g.edge\_index\])
array(\[\[ 8687, 66, 179681\],\
\[ 20369, 66, 255033\],\
\[ 38674, 66, 300230\]\])
get\_all\_edges(_v_, _eprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_all_edges)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_all_edges "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in- and out-edges of vertex v, and optional edge properties list `eprops`. The shape of the array will be `(E, 2 + len(eprops))`, where `E` is the number of edges, and each line will contain the source, target and the edge property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_all\_edges(66, \[g.edge\_index\])
array(\[\[ 66, 63, 5266\],\
\[ 66, 20369, 5267\],\
\[ 66, 13980, 5268\],\
\[ 66, 8687, 5269\],\
\[ 66, 38674, 5270\],\
\[ 8687, 66, 179681\],\
\[ 20369, 66, 255033\],\
\[ 38674, 66, 300230\]\])
get\_out\_neighbors(_v_, _vprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_out_neighbors)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_out_neighbors "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the out-neighbors of vertex `v`, and optional vertex properties list `vprops`. If `vprops` is not empty, the shape of the array will be `(V, 1 + len(eprops))`, where `V` is the number of vertices, and each line will contain a vertex and its property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_out\_neighbors(66)
array(\[ 63, 20369, 13980, 8687, 38674\])
get\_in\_neighbors(_v_, _vprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_in_neighbors)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_in_neighbors "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-neighbors of vertex `v`, and optional vertex properties list `vprops`. If `vprops` is not empty, the shape of the array will be `(V, 1 + len(eprops))`, where `V` is the number of vertices, and each line will contain a vertex and its property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_in\_neighbors(66)
array(\[ 8687, 20369, 38674\])
get\_all\_neighbors(_v_, _vprops\=\[\]_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_all_neighbors)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_all_neighbors "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-neighbors and out-neighbors of vertex `v`, and optional vertex properties list `vprops`. If `vprops` is not empty, the shape of the array will be `(V, 1 + len(eprops))`, where `V` is the number of vertices, and each line will contain a vertex and its property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_all\_neighbors(66)
array(\[ 63, 20369, 13980, 8687, 38674, 8687, 20369, 38674\])
get\_out\_degrees(_vs_, _eweight\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_out_degrees)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_out_degrees "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the out-degrees of vertex list `vs`. If supplied, the degrees will be weighted according to the edge [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
`eweight`.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_out\_degrees(\[42, 666\])
array(\[20, 38\], dtype=uint64)
get\_in\_degrees(_vs_, _eweight\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_in_degrees)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_in_degrees "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-degrees of vertex list `vs`. If supplied, the degrees will be weighted according to the edge [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
`eweight`.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_in\_degrees(\[42, 666\])
array(\[20, 39\], dtype=uint64)
get\_total\_degrees(_vs_, _eweight\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_total_degrees)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_total_degrees "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the total degrees (i.e. in- plus out-degree) of vertex list `vs`. If supplied, the degrees will be weighted according to the edge [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
`eweight`.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_total\_degrees(\[42, 666\])
array(\[40, 77\], dtype=uint64)
get\_edge\_range(_s_, _t_, _eprops_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_edge_range)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_edge_range "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the parallel edge properties `eprops` for the parallel edges between vertices `s` and `t`.
The shape of the array will be `(m, len(eprops))`, where `m` is the number of parallele edges, and each line will contain the edge property values.
This operation normally will take \\(O(\\times\\min(k(s), k(t)))\\) time, where \\(k(s)\\) and \\(k(t)\\) are the out-degree and in-degree (or out-degree if undirected) of vertices \\(s\\) and \\(t\\). However, if [`set_fast_edge_lookup()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_lookup "graph_tool.Graph.set_fast_edge_lookup")
is set to True, this operation becomes \\(O(m)\\), where \\(m\\) being the number of parallel edges.
Note
The order of the edges is identical to [`edge()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge "graph_tool.Graph.edge")
.
Examples
\>>> g \= gt.Graph(\[(0, 1), (0, 1)\])
\>>> g.get\_edge\_range(0, 1, \[g.edge\_index\])
array(\[\[0\],\
\[1\]\])
Obtaining vertex and edge descriptors
vertex(_i_, _use\_index\=True_, _add\_missing\=False_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.vertex)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex "Link to this definition")
Return the vertex with index `i`. If `use_index=False`, the `i`\-th vertex is returned (which can differ from the vertex with index `i` in case of filtered graphs).
If `add_missing == True`, and the vertex does not exist in the graph, the necessary number of missing vertices are inserted, and the new vertex is returned.
edge(_s_, _t_, _all\_edges\=False_, _add\_missing\=False_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.edge)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge "Link to this definition")
Return the edge from vertex `s` to `t`, if it exists. If `all_edges=True` then a list is returned with all the parallel edges from `s` to `t`, otherwise only one edge is returned.
If `add_missing == True`, a new edge is created and returned, if none currently exists.
This operation normally will take \\(O(\\min(k(s), k(t)))\\) time, where \\(k(s)\\) and \\(k(t)\\) are the out-degree and in-degree (or out-degree if undirected) of vertices \\(s\\) and \\(t\\). However, if [`set_fast_edge_lookup()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_lookup "graph_tool.Graph.set_fast_edge_lookup")
is set to True, this operation becomes \\(O(1)\\).
set\_fast\_edge\_lookup(_fast\=True_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.set_fast_edge_lookup)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_lookup "Link to this definition")
If `fast == True` the fast \\(O(1)\\) lookup of edges will be enabled. This requires an additional data structure of size \\(O(E)\\) to be kept at all times. If `fast == False`, this data structure is destroyed.
get\_fast\_edge\_lookup()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_fast_edge_lookup)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_fast_edge_lookup "Link to this definition")
Return whether the fast \\(O(1)\\) lookup of edges is currently enabled.
Number of vertices and edges
num\_vertices(_ignore\_filter\=False_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.num_vertices)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.num_vertices "Link to this definition")
Get the number of vertices.
If `ignore_filter == True`, vertex filters are ignored.
Note
If the vertices are being filtered, and `ignore_filter == False`, this operation is \\(O(V)\\). Otherwise it is \\(O(1)\\).
num\_edges(_ignore\_filter\=False_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.num_edges)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.num_edges "Link to this definition")
Get the number of edges.
If `ignore_filter == True`, edge filters are ignored.
Note
If the edges are being filtered, and `ignore_filter == False`, this operation is \\(O(E)\\). Otherwise it is \\(O(1)\\).
Modifying vertices and edges
The following functions allow for addition and removal of vertices in the graph.
add\_vertex(_n\=1_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.add_vertex)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_vertex "Link to this definition")
Add a vertex to the graph, and return it. If `n != 1`, `n` vertices are inserted and an iterator over the new vertices is returned. This operation is \\(O(n)\\).
remove\_vertex(_vertex_, _fast\=False_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.remove_vertex)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.remove_vertex "Link to this definition")
Remove a vertex from the graph. If `vertex` is an iterable, it should correspond to a sequence of vertices to be removed.
Note
If the option `fast == False` is given, this operation is \\(O(V + E)\\) (this is the default). Otherwise it is \\(O(k + k\_{\\text{last}})\\), where \\(k\\) is the (total) degree of the vertex being deleted, and \\(k\_{\\text{last}}\\) is the (total) degree of the vertex with the largest index.
Warning
This operation may invalidate vertex descriptors. Vertices are always indexed contiguously in the range \\(\[0, N-1\]\\), hence vertex descriptors with an index higher than `vertex` will be invalidated after removal (if `fast == False`, otherwise only descriptors pointing to vertices with the largest index will be invalidated).
Because of this, the only safe way to remove more than one vertex at once is to sort them in decreasing index order:
\# 'del\_list' is a list of vertex descriptors
for v in reversed(sorted(del\_list)):
g.remove\_vertex(v)
Alternatively (and preferably), a list (or iterable) may be passed directly as the `vertex` parameter, and the above is performed internally (in C++).
Warning
If `fast == True`, the vertex being deleted is ‘swapped’ with the last vertex (i.e. with the largest index), which will in turn inherit the index of the vertex being deleted. All property maps associated with the graph will be properly updated, but the index ordering of the graph will no longer be the same.
The following functions allow for addition and removal of edges in the graph.
add\_edge(_source_, _target_, _add\_missing\=True_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.add_edge)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_edge "Link to this definition")
Add a new edge from `source` to `target` to the graph, and return it. This operation is \\(O(1)\\).
If `add_missing == True`, the source and target vertices are included in the graph if they don’t yet exist.
remove\_edge(_edge_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.remove_edge)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.remove_edge "Link to this definition")
Remove an edge from the graph.
Note
This operation is normally \\(O(k\_s + k\_t)\\), where \\(k\_s\\) and \\(k\_t\\) are the total degrees of the source and target vertices, respectively. However, if [`set_fast_edge_removal()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_removal "graph_tool.Graph.set_fast_edge_removal")
is set to True, this operation becomes \\(O(1)\\).
Warning
The relative ordering of the remaining edges in the graph is kept unchanged, unless [`set_fast_edge_removal()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_removal "graph_tool.Graph.set_fast_edge_removal")
is set to True, in which case it can change.
add\_edge\_list(_edge\_list_, _hashed\=False_, _hash\_type\='string'_, _eprops\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.add_edge_list)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.add_edge_list "Link to this definition")
Add a list of edges to the graph, given by `edge_list`, which can be an iterator of `(source, target)` pairs where both `source` and `target` are vertex indices (or can be so converted), or a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
of shape `(E,2)`, where `E` is the number of edges, and each line specifies a `(source, target)` pair. If the list references vertices which do not exist in the graph, they will be created.
Optionally, if `hashed == True`, the vertex values in the edge list are not assumed to correspond to vertex indices directly. In this case they will be mapped to vertex indices according to the order in which they are encountered, and a vertex property map with the vertex values is returned. The option `hash_type` will determine the expected type used by the hash keys, and they can be any property map value type (see [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
), unless `edge_list` is a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
, in which case the value of this option is ignored, and the type is determined automatically.
If `hashed == False` and the target value of an edge corresponds to the maximum interger value ([`sys.maxsize`](https://docs.python.org/3/library/sys.html#sys.maxsize "(in Python v3.13)")
, or the maximum integer type of the [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
object), or is a [`numpy.nan`](https://numpy.org/doc/stable/reference/constants.html#numpy.nan "(in NumPy v2.3)")
or [`numpy.inf`](https://numpy.org/doc/stable/reference/constants.html#numpy.inf "(in NumPy v2.3)")
value, then only the source vertex will be added to the graph.
If `hashed == True`, and the target value corresponds to `None`, then only the source vertex will be added to the graph.
If given, `eprops` should specify an iterable containing edge property maps that will be filled with the remaining values at each row, if there are more than two. Alternatively, `eprops` can contain a list of `(name, value_type)` pairs, in which case new internal dege property maps will be created with the corresponding name name and value type.
Note
If `edge_list` is a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
object, the execution of this function will be done entirely in C++, and hence much faster.
Examples
\>>> edge\_list \= \[(0, 1, .3, 10), (2, 3, .1, 0), (2, 0, .4, 42)\]
\>>> g \= gt.Graph()
\>>> eweight \= g.new\_ep("double")
\>>> elayer \= g.new\_ep("int")
\>>> g.add\_edge\_list(edge\_list, eprops\=\[eweight, elayer\])
\>>> print(eweight.fa)
\[0.3 0.1 0.4\]
\>>> g.get\_edges()
array(\[\[0, 1\],\
\[2, 3\],\
\[2, 0\]\])
set\_fast\_edge\_removal(_fast\=True_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.set_fast_edge_removal)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_removal "Link to this definition")
If `fast == True` the fast \\(O(1)\\) removal of edges will be enabled. This requires an additional data structure of size \\(O(E)\\) to be kept at all times. If `fast == False`, this data structure is destroyed.
get\_fast\_edge\_removal()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_fast_edge_removal)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_fast_edge_removal "Link to this definition")
Return whether the fast \\(O(1)\\) removal of edges is currently enabled.
The following functions allow for easy removal of vertices and edges from the graph.
clear()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.clear)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.clear "Link to this definition")
Remove all vertices and edges from the graph.
clear\_vertex(_vertex_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.clear_vertex)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.clear_vertex "Link to this definition")
Remove all in and out-edges from the given vertex.
clear\_edges()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.clear_edges)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.clear_edges "Link to this definition")
Remove all edges from the graph.
After the removal of many edges and/or vertices, the underlying containers may have a capacity that significantly exceeds the size of the graph. The function below corrects this.
shrink\_to\_fit()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.shrink_to_fit)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.shrink_to_fit "Link to this definition")
Force the physical capacity of the underlying containers to match the graph’s actual size, potentially freeing memory back to the system.
Directedness and reversal of edges
Note
These functions do not actually modify the graph, and are fully reversible. They are also very cheap, with an \\(O(1)\\) complexity.
set\_directed(_is\_directed_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.set_directed)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_directed "Link to this definition")
Set the directedness of the graph.
Note
This is a \\(O(1)\\) operation that does not modify the storage of the graph.
Warning
Changing directedness will invalidate existing vertex and edge descriptors, which will still point to the original graph.
is\_directed()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.is_directed)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.is_directed "Link to this definition")
Get the directedness of the graph.
set\_reversed(_is\_reversed_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.set_reversed)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_reversed "Link to this definition")
Reverse the direction of the edges, if `is_reversed` is `True`, or maintain the original direction otherwise.
Note
This is a \\(O(1)\\) operation that does not modify the storage of the graph.
Warning
Reversing the graph will invalidate existing vertex and edge descriptors, which will still point to the original graph.
is\_reversed()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.is_reversed)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.is_reversed "Link to this definition")
Return `True` if the edges are reversed, and `False` otherwise.
Creation of new property maps
new\_property(_key\_type_, _value\_type_, _vals\=None_, _val\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.new_property)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_property "Link to this definition")
Create a new (uninitialized) vertex property map of key type `key_type` (`v`, `e` or `g`), value type `value_type`, and return it. If provided, the values will be initialized by `vals`, which should be a sequence, or by `val` which should be a single value.
new\_vertex\_property(_value\_type_, _vals\=None_, _val\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.new_vertex_property)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_vertex_property "Link to this definition")
Create a new vertex property map of type `value_type`, and return it. If provided, the values will be initialized by `vals`, which should be sequence or by `val` which should be a single value.
new\_vp(_value\_type_, _vals\=None_, _val\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_vp "Link to this definition")
Alias to [`new_vertex_property()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_vertex_property "graph_tool.Graph.new_vertex_property")
.
new\_edge\_property(_value\_type_, _vals\=None_, _val\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.new_edge_property)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_edge_property "Link to this definition")
Create a new edge property map of type `value_type`, and return it. If provided, the values will be initialized by `vals`, which should be sequence or by `val` which should be a single value.
new\_ep(_value\_type_, _vals\=None_, _val\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_ep "Link to this definition")
Alias to [`new_edge_property()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_edge_property "graph_tool.Graph.new_edge_property")
.
new\_graph\_property(_value\_type_, _val\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.new_graph_property)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_graph_property "Link to this definition")
Create a new graph property map of type `value_type`, and return it. If `val` is not None, the property is initialized to its value.
new\_gp(_value\_type_, _val\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_gp "Link to this definition")
Alias to [`new_graph_property()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_graph_property "graph_tool.Graph.new_graph_property")
.
New property maps can be created by copying already existing ones.
copy\_property(_src_, _tgt\=None_, _value\_type\=None_, _g\=None_, _full\=True_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.copy_property)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.copy_property "Link to this definition")
Copy contents of `src` property to `tgt` property. If `tgt` is None, then a new property map of the same type (or with the type given by the optional `value_type` parameter) is created, and returned. The optional parameter `g` specifies the source graph to copy properties from (defaults to the graph than owns src). If `full == False`, then in the case of filtered graphs only the unmasked values are copied (with the remaining ones taking the type-dependent default value).
Note
In case the source property map belongs to different graphs, this function behaves as follows.
For vertex properties, the source and target graphs must have the same number of vertices, and the properties are copied according to the index values.
For edge properties, the edge index is not important, and the properties are copied by matching edges between the different graphs according to the source and target vertex indices. In case the graph has parallel edges with the same source and target vertices, they are matched according to their iteration order. The edge sets do not have to be the same between source and target graphs, as the copying occurs only for edges that lie at their intersection.
degree\_property\_map(_deg_, _weight\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.degree_property_map)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.degree_property_map "Link to this definition")
Create and return a vertex property map containing the degree type given by `deg`, which can be any of `"in"`, `"out"`, or `"total"`. If provided, `weight` should be an edge [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
containing the edge weights which should be summed.
Index property maps
vertex\_index[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex_index "Link to this definition")
Vertex index map.
It maps for each vertex in the graph an unique integer in the range \[0, [`num_vertices()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.num_vertices "graph_tool.Graph.num_vertices")\
- 1\].
Note
Like [`edge_index`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge_index "graph_tool.Graph.edge_index")
, this is a special instance of a [`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
class, which is **immutable**, and cannot be accessed as an array.
edge\_index[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge_index "Link to this definition")
Edge index map.
It maps for each edge in the graph an unique integer.
Note
Like [`vertex_index`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex_index "graph_tool.Graph.vertex_index")
, this is a special instance of a [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
class, which is **immutable**, and cannot be accessed as an array.
Additionally, the indices may not necessarily lie in the range \[0, [`num_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.num_edges "graph_tool.Graph.num_edges")\
- 1\]. However this will always happen whenever no edges are deleted from the graph.
edge\_index\_range[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge_index_range "Link to this definition")
The size of the range of edge indices.
reindex\_edges()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.reindex_edges)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.reindex_edges "Link to this definition")
Reset the edge indices so that they lie in the \[0, [`num_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.num_edges "graph_tool.Graph.num_edges")\
- 1\] range. The index ordering will be compatible with the sequence returned by the [`edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edges "graph_tool.Graph.edges")
function.
Warning
Calling this function will invalidate all existing edge property maps, if the index ordering is modified! The property maps will still be usable, but their contents will still be tied to the old indices, and thus may become scrambled.
Internal property maps
Internal property maps are just like regular property maps, with the only exception that they are saved and loaded to/from files together with the graph itself. See [internal property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-internal-props)
for more details.
Note
All dictionaries below are mutable. However, any dictionary returned below is only an one-way proxy to the internally-kept properties. If you modify this object, the change will be propagated to the internal dictionary, but not vice-versa. Keep this in mind if you intend to keep a copy of the returned object.
properties[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.properties "Link to this definition")
Dictionary of internal properties. Keys must always be a tuple, where the first element if a string from the set `{'v', 'e', 'g'}`, representing a vertex, edge or graph property, respectively, and the second element is the name of the property map.
Examples
\>>> g \= gt.Graph()
\>>> g.properties\[("e", "foo")\] \= g.new\_edge\_property("vector")
\>>> del g.properties\[("e", "foo")\]
vertex\_properties[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex_properties "Link to this definition")
Dictionary of internal vertex properties. The keys are the property names.
vp[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vp "Link to this definition")
Alias to [`vertex_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex_properties "graph_tool.Graph.vertex_properties")
.
edge\_properties[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge_properties "Link to this definition")
Dictionary of internal edge properties. The keys are the property names.
ep[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.ep "Link to this definition")
Alias to [`edge_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge_properties "graph_tool.Graph.edge_properties")
.
graph\_properties[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.graph_properties "Link to this definition")
Dictionary of internal graph properties. The keys are the property names.
gp[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.gp "Link to this definition")
Alias to [`graph_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.graph_properties "graph_tool.Graph.graph_properties")
.
own\_property(_prop_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.own_property)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.own_property "Link to this definition")
Return a version of the property map ‘prop’ (possibly belonging to another graph) which is owned by the current graph.
list\_properties()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.list_properties)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.list_properties "Link to this definition")
Print a list of all internal properties.
Examples
\>>> g \= gt.Graph()
\>>> g.properties\[("e", "foo")\] \= g.new\_edge\_property("vector")
\>>> g.vertex\_properties\["foo"\] \= g.new\_vertex\_property("double")
\>>> g.vertex\_properties\["bar"\] \= g.new\_vertex\_property("python::object")
\>>> g.graph\_properties\["gnat"\] \= g.new\_graph\_property("string", "hi there!")
\>>> g.list\_properties()
gnat (graph) (type: string, val: hi there!)
bar (vertex) (type: python::object)
foo (vertex) (type: double)
foo (edge) (type: vector)
Filtering of vertices and edges.
See [Graph filtering](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-graph-filtering)
for more details.
Note
These functions do not actually modify the graph, and are fully reversible. They are also very cheap, and have an \\(O(1)\\) complexity.
set\_filters(_eprop_, _vprop_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.set_filters)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_filters "Link to this definition")
Set the boolean properties for edge and vertex filters, respectively. Only the vertices and edges with value different than `False` are kept in the filtered graph. If any of the supplied properties is `None`, an empty filter is constructed which allows all edges or vertices.
Note
This is a \\(O(1)\\) operation that does not modify the storage of the graph.
Warning
Setting vertex or edge filters will invalidate existing vertex and edge descriptors, which will still point to the unfiltered graph.
set\_vertex\_filter(_prop_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.set_vertex_filter)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_vertex_filter "Link to this definition")
Set the vertex boolean filter property. Only the vertices with value different than `False` are kept in the filtered graph. If the supplied property is `None`, the filter is replaced by an uniform filter allowing all vertices.
Note
This is a \\(O(1)\\) operation that does not modify the storage of the graph.
Warning
Setting vertex filters will invalidate existing vertex and edge descriptors, which will still point to the unfiltered graph.
get\_vertex\_filter()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_vertex_filter)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_vertex_filter "Link to this definition")
Return the vertex filter property.
set\_edge\_filter(_prop_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.set_edge_filter)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_edge_filter "Link to this definition")
Set the edge boolean filter property. Only the edges with value different than `False` are kept in the filtered graph. If the supplied property is `None`, the filter is replaced by an uniform filter allowing all edges.
Note
This is a \\(O(1)\\) operation that does not modify the storage of the graph.
Warning
Setting edge filters will invalidate existing vertex and edge descriptors, which will still point to the unfiltered graph.
get\_edge\_filter()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.get_edge_filter)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.get_edge_filter "Link to this definition")
Return the edge filter property map.
clear\_filters()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.clear_filters)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.clear_filters "Link to this definition")
Remove vertex and edge filters, and set the graph to the unfiltered state.
Note
This is a \\(O(1)\\) operation that does not modify the storage of the graph.
Warning
Clearing vertex and edge filters will invalidate existing vertex and edge descriptors.
Warning
The purge functions below irreversibly remove the filtered vertices or edges from the graph. Note that, contrary to the functions above, these are \\(O(V)\\) and \\(O(E)\\) operations, respectively.
purge\_vertices(_in\_place\=False_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.purge_vertices)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.purge_vertices "Link to this definition")
Remove all vertices of the graph which are currently being filtered out. This operation is not reversible.
If the option `in_place == True` is given, the algorithm will remove the filtered vertices and re-index all property maps which are tied with the graph. This is a slow operation which has an \\(O(V^2)\\) complexity.
If `in_place == False`, the graph and its vertex and edge property maps are temporarily copied to a new unfiltered graph, which will replace the contents of the original graph. This is a fast operation with an \\(O(V + E)\\) complexity. This is the default behaviour if no option is given.
purge\_edges()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.purge_edges)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.purge_edges "Link to this definition")
Remove all edges of the graph which are currently being filtered out. This operation is not reversible.
I/O operations
See [Graph I/O](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-graph-io)
for more details.
load(_file\_name_, _fmt\='auto'_, _ignore\_vp\=None_, _ignore\_ep\=None_, _ignore\_gp\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.load)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.load "Link to this definition")
Load graph from `file_name` (which can be either a string or a file-like object). The format is guessed from `file_name`, or can be specified by `fmt`, which can be either “gt”, “graphml”, “xml”, “dot” or “gml”. (Note that “graphml” and “xml” are synonyms).
If provided, the parameters `ignore_vp`, `ignore_ep` and `ignore_gp`, should contain a list of property names (vertex, edge or graph, respectively) which should be ignored when reading the file.
Warning
The only file formats which are capable of perfectly preserving the internal property maps are “gt” and “graphml”. Because of this, they should be preferred over the other formats whenever possible.
save(_file\_name_, _fmt\='auto'_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#Graph.save)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.save "Link to this definition")
Save graph to `file_name` (which can be either a string or a file-like object). The format is guessed from the `file_name`, or can be specified by `fmt`, which can be either “gt”, “graphml”, “xml”, “dot” or “gml”. (Note that “graphml” and “xml” are synonyms).
Warning
The only file formats which are capable of perfectly preserving the internal property maps are “gt” and “graphml”. Because of this, they should be preferred over the other formats whenever possible.
Contents
---
# EdgePropertyMap — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.EdgePropertyMap.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.EdgePropertyMap.rst "Download source file")
* .pdf
EdgePropertyMap
===============
Contents
--------
EdgePropertyMap[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#edgepropertymap "Link to this heading")
=======================================================================================================================================================
_class_ graph\_tool.EdgePropertyMap(_pmap_, _g_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#EdgePropertyMap)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "Link to this definition")
Bases: [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
This class provides a mapping from edges to arbitrary properties.
See [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-maps)
and [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
for more details.
Methods
| | |
| --- | --- |
| [`coerce_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.coerce_type "graph_tool.EdgePropertyMap.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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.copy "graph_tool.EdgePropertyMap.copy")
(\[value\_type, full\]) | Return a copy of the property map. |
| [`data_ptr`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.data_ptr "graph_tool.EdgePropertyMap.data_ptr")
() | Return the pointer to memory where the data resides. |
| [`get_2d_array`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.get_2d_array "graph_tool.EdgePropertyMap.get_2d_array")
(\[pos, dtype\]) | 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, which contains a copy of all entries of the vector-valued property map. |
| [`get_array`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.get_array "graph_tool.EdgePropertyMap.get_array")
() | Get a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
subclass ([`PropertyArray`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "graph_tool.PropertyArray")
) pointint to the property values. |
| [`get_graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.get_graph "graph_tool.EdgePropertyMap.get_graph")
() | Get the graph class to which the map refers. |
| [`is_writable`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.is_writable "graph_tool.EdgePropertyMap.is_writable")
() | Return True if the property is writable. |
| [`key_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.key_type "graph_tool.EdgePropertyMap.key_type")
() | Return the key type of the map. |
| [`python_value_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.python_value_type "graph_tool.EdgePropertyMap.python_value_type")
() | Return the python-compatible value type of the map. |
| [`reserve`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.reserve "graph_tool.EdgePropertyMap.reserve")
(size) | Reserve enough space for `size` elements in underlying container. |
| [`resize`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.resize "graph_tool.EdgePropertyMap.resize")
(size) | Resize the underlying container to contain exactly `size` elements. |
| [`set_2d_array`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.set_2d_array "graph_tool.EdgePropertyMap.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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.set_value "graph_tool.EdgePropertyMap.set_value")
(val) | Sets all values in the property map to the same `val`. |
| [`set_values`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.set_values "graph_tool.EdgePropertyMap.set_values")
(vals) | Sets values in the property map to the iterable `vals`. |
| [`shrink_to_fit`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.shrink_to_fit "graph_tool.EdgePropertyMap.shrink_to_fit")
() | Shrink size of underlying container to accommodate only the necessary amount, and thus potentially freeing memory. |
| [`swap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.swap "graph_tool.EdgePropertyMap.swap")
(other) | Swap internal storage with `other`. |
| [`t`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.t "graph_tool.EdgePropertyMap.t")
(f\[, value\_type, no\_array, inplace\]) | Alias to [`transform()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.transform "graph_tool.PropertyMap.transform")
. |
| [`transform`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.transform "graph_tool.EdgePropertyMap.transform")
(f\[, value\_type, no\_array, inplace\]) | Return a copy of the property map with the values transformed by the user-supplied function `f`. |
| [`value_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.value_type "graph_tool.EdgePropertyMap.value_type")
() | Return the value type of the map. |
Attributes
| | |
| --- | --- |
| [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.a "graph_tool.EdgePropertyMap.a") | Shortcut to the [`get_array()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_array "graph_tool.PropertyMap.get_array")
method as an attribute. |
| [`fa`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.fa "graph_tool.EdgePropertyMap.fa") | The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, but instead an _indexed_ array is returned, which contains only entries for vertices/edges which are not filtered out. |
| [`ma`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.ma "graph_tool.EdgePropertyMap.ma") | The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, but instead a [`numpy.ma.MaskedArray`](https://numpy.org/doc/stable/reference/maskedarray.baseclass.html#numpy.ma.MaskedArray "(in NumPy v2.3)")
object is returned, which contains only entries for vertices/edges which are not filtered out. |
coerce\_type(_full\=True_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.coerce_type "Link to this definition")
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_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.copy "Link to this definition")
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()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.data_ptr "Link to this definition")
Return the pointer to memory where the data resides.
get\_2d\_array(_pos\=None_, _dtype\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.get_2d_array "Link to this definition")
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, which 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.
If `pos` is not given (the default), then it will be assumed to correspond to the entire range of the first entry in the map.
The parameter `dtype` determines the desired data-type for the array. If not given, it will be determined automatically (by applying promotion rules when necessary.)
get\_array()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.get_array "Link to this definition")
Get a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
subclass ([`PropertyArray`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "graph_tool.PropertyArray")
) pointint to 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()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_2d_array "graph_tool.PropertyMap.get_2d_array")
and [`set_2d_array()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.set_2d_array "graph_tool.PropertyMap.set_2d_array")
member functions.
Warning
This function does not copy the data from the property map, and therefore runs in \\(O(1)\\) time.
As a consequence, 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()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.get_graph "Link to this definition")
Get the graph class to which the map refers.
is\_writable()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.is_writable "Link to this definition")
Return True if the property is writable.
key\_type()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.key_type "Link to this definition")
Return the key type of the map. Either ‘g’, ‘v’ or ‘e’.
python\_value\_type()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.python_value_type "Link to this definition")
Return the python-compatible value type of the map.
reserve(_size_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.reserve "Link to this definition")
Reserve enough space for `size` elements in underlying container. If the original size is already equal or larger, nothing will happen.
resize(_size_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.resize "Link to this definition")
Resize the underlying container to contain exactly `size` elements.
set\_2d\_array(_a_, _pos\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.set_2d_array "Link to this definition")
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_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.set_value "Link to this definition")
Sets all values in the property map to the same `val`.
set\_values(_vals_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.set_values "Link to this definition")
Sets values in the property map to the iterable `vals`.
shrink\_to\_fit()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.shrink_to_fit "Link to this definition")
Shrink size of underlying container to accommodate only the necessary amount, and thus potentially freeing memory.
swap(_other_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.swap "Link to this definition")
Swap internal storage with `other`.
t(_f_, _value\_type\=None_, _no\_array\=False_, _inplace\=False_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.t "Link to this definition")
Alias to [`transform()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.transform "graph_tool.PropertyMap.transform")
.
transform(_f_, _value\_type\=None_, _no\_array\=False_, _inplace\=False_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.transform "Link to this definition")
Return a copy of the property map with the values transformed by the user-supplied function `f`. If given, `value_type` specifies the value type for the new property map.
If the value type of the original map allows, the values will be passed to `f` as a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
, unless no\_array is `True`. Otherwise, they will be passed individually.
If `inplace == True` the transformation happens in-place, without copying the property map. In this case the parameter `value_type` is ignored.
value\_type()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.value_type "Link to this definition")
Return the value type of the map.
a[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.a "Link to this definition")
Shortcut to the [`get_array()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_array "graph_tool.PropertyMap.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[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.fa "Link to this definition")
The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute.
Warning
Because [advanced indexing](https://numpy.org/doc/stable/user/basics.indexing.html#advanced-indexing "(in NumPy v2.3)")
is triggered, a **copy** of the array is returned, not a view, as is the case for the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute. Nevertheless, the assignment of values to the _whole_ array at once works as expected.
Importantly, this means that this operation runs in time \\(O(N)\\) or O(N + E) for node and edge properties, respectively, where \\(N\\) is the number of vertices and \\(E\\) the number of edges in the unfiltered graph, and therefore can be significantly slower than using the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, which runs in time \\(O(1)\\).
ma[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap.ma "Link to this definition")
The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, but instead a [`numpy.ma.MaskedArray`](https://numpy.org/doc/stable/reference/maskedarray.baseclass.html#numpy.ma.MaskedArray "(in NumPy v2.3)")
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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "graph_tool.PropertyArray")
is returned, which is identical to the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute.
Warning
Unlike [`fa`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.fa "graph_tool.PropertyMap.fa")
, the masked array does _not_ copy the property map values.
This function runs in time \\(O(N)\\) or O(N + E) for node and edge properties, respectively, where \\(N\\) is the number of vertices and \\(E\\) the number of edges in the unfiltered graph.
Contents
---
# GraphView — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.GraphView.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.GraphView.rst "Download source file")
* .pdf
GraphView
=========
Contents
--------
GraphView[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graphview "Link to this heading")
=====================================================================================================================================
_class_ graph\_tool.GraphView(_g_, _vfilt\=None_, _efilt\=None_, _directed\=None_, _reversed\=False_, _skip\_properties\=False_, _skip\_vfilt\=False_, _skip\_efilt\=False_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#GraphView)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView "Link to this definition")
Bases: [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
A view of selected vertices or edges of another graph.
This class uses shared data from another [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
instance, but allows for local filtering of vertices and/or edges, edge directionality or reversal. See [Graph views](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-graph-views)
for more details and examples.
The existence of a [`GraphView`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView "graph_tool.GraphView")
object does not affect the original graph, except if the graph view is modified (addition or removal of vertices or edges), in which case the modification is directly reflected in the original graph (and vice-versa), since they both point to the same underlying data. Because of this, instances of [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
can be used interchangeably with a graph and its views.
The argument `g` must be an instance of a [`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
class. If specified, `vfilt` and `efilt` select which vertices and edges are filtered, respectively. These parameters can either be a boolean-valued [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
or [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
, which specify which vertices/edges are selected, or an unary function that returns `True` if a given vertex/edge is to be selected, or `False` otherwise.
The boolean parameter `directed` can be used to set the directionality of the graph view. If `directed is None`, the directionality is inherited from `g`.
If `reversed == True`, the direction of the edges is reversed.
If `vfilt` or `efilt` is anything other than a [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
instance, the instantiation running time is \\(O(V)\\) and \\(O(E)\\), respectively. Otherwise, the running time is \\(O(1)\\).
If either `skip_properties`, `skip_vfilt` or `skip_efilt` is `True`, then the internal properties, vertex filter or edge filter of the original graph are ignored, respectively.
Methods
| | |
| --- | --- |
| [`add_edge`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.add_edge "graph_tool.GraphView.add_edge")
(source, target\[, add\_missing\]) | Add a new edge from `source` to `target` to the graph, and return it. |
| [`add_edge_list`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.add_edge_list "graph_tool.GraphView.add_edge_list")
(edge\_list\[, hashed, ...\]) | Add a list of edges to the graph, given by `edge_list`, which can be an iterator of `(source, target)` pairs where both `source` and `target` are vertex indices (or can be so converted), or a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
of shape `(E,2)`, where `E` is the number of edges, and each line specifies a `(source, target)` pair. |
| [`add_vertex`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.add_vertex "graph_tool.GraphView.add_vertex")
(\[n\]) | Add a vertex to the graph, and return it. |
| [`clear`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.clear "graph_tool.GraphView.clear")
() | Remove all vertices and edges from the graph. |
| [`clear_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.clear_edges "graph_tool.GraphView.clear_edges")
() | Remove all edges from the graph. |
| [`clear_filters`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.clear_filters "graph_tool.GraphView.clear_filters")
() | Remove vertex and edge filters, and set the graph to the unfiltered state. |
| [`clear_vertex`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.clear_vertex "graph_tool.GraphView.clear_vertex")
(vertex) | Remove all in and out-edges from the given vertex. |
| [`copy`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.copy "graph_tool.GraphView.copy")
() | Return a deep copy of self. |
| [`copy_property`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.copy_property "graph_tool.GraphView.copy_property")
(src\[, tgt, value\_type, g, full\]) | Copy contents of `src` property to `tgt` property. |
| [`degree_property_map`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.degree_property_map "graph_tool.GraphView.degree_property_map")
(deg\[, weight\]) | Create and return a vertex property map containing the degree type given by `deg`, which can be any of `"in"`, `"out"`, or `"total"`. |
| [`edge`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.edge "graph_tool.GraphView.edge")
(s, t\[, all\_edges, add\_missing\]) | Return the edge from vertex `s` to `t`, if it exists. |
| [`edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.edges "graph_tool.GraphView.edges")
() | Return an [`iterator`](https://docs.python.org/3/library/stdtypes.html#iterator.__iter__ "(in Python v3.13)")
over the edges. |
| [`get_all_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_all_edges "graph_tool.GraphView.get_all_edges")
(v\[, eprops\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in- and out-edges of vertex v, and optional edge properties list `eprops`. |
| [`get_all_neighbors`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_all_neighbors "graph_tool.GraphView.get_all_neighbors")
(v\[, vprops\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-neighbors and out-neighbors of vertex `v`, and optional vertex properties list `vprops`. |
| [`get_all_neighbours`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_all_neighbours "graph_tool.GraphView.get_all_neighbours")
(v\[, vprops\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-neighbors and out-neighbors of vertex `v`, and optional vertex properties list `vprops`. |
| [`get_edge_filter`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_edge_filter "graph_tool.GraphView.get_edge_filter")
() | Return the edge filter property map. |
| [`get_edge_range`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_edge_range "graph_tool.GraphView.get_edge_range")
(s, t, eprops) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the parallel edge properties `eprops` for the parallel edges between vertices `s` and `t`. |
| [`get_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_edges "graph_tool.GraphView.get_edges")
(\[eprops\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the edges, and optional edge properties list `eprops`. |
| [`get_fast_edge_lookup`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_fast_edge_lookup "graph_tool.GraphView.get_fast_edge_lookup")
() | Return whether the fast \\(O(1)\\) lookup of edges is currently enabled. |
| [`get_fast_edge_removal`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_fast_edge_removal "graph_tool.GraphView.get_fast_edge_removal")
() | Return whether the fast \\(O(1)\\) removal of edges is currently enabled. |
| [`get_filter_state`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_filter_state "graph_tool.GraphView.get_filter_state")
() | Return a copy of the filter state of the graph. |
| [`get_in_degrees`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_in_degrees "graph_tool.GraphView.get_in_degrees")
(vs\[, eweight\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-degrees of vertex list `vs`. |
| [`get_in_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_in_edges "graph_tool.GraphView.get_in_edges")
(v\[, eprops\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-edges of vertex `v`, and optional edge properties list `eprops`. |
| [`get_in_neighbors`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_in_neighbors "graph_tool.GraphView.get_in_neighbors")
(v\[, vprops\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-neighbors of vertex `v`, and optional vertex properties list `vprops`. |
| [`get_in_neighbours`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_in_neighbours "graph_tool.GraphView.get_in_neighbours")
(v\[, vprops\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-neighbors of vertex `v`, and optional vertex properties list `vprops`. |
| [`get_out_degrees`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_out_degrees "graph_tool.GraphView.get_out_degrees")
(vs\[, eweight\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the out-degrees of vertex list `vs`. |
| [`get_out_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_out_edges "graph_tool.GraphView.get_out_edges")
(v\[, eprops\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the out-edges of vertex `v`, and optional edge properties list `eprops`. |
| [`get_out_neighbors`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_out_neighbors "graph_tool.GraphView.get_out_neighbors")
(v\[, vprops\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the out-neighbors of vertex `v`, and optional vertex properties list `vprops`. |
| [`get_out_neighbours`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_out_neighbours "graph_tool.GraphView.get_out_neighbours")
(v\[, vprops\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the out-neighbors of vertex `v`, and optional vertex properties list `vprops`. |
| [`get_total_degrees`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_total_degrees "graph_tool.GraphView.get_total_degrees")
(vs\[, eweight\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the total degrees (i.e. in- plus out-degree) of vertex list `vs`. |
| [`get_vertex_filter`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_vertex_filter "graph_tool.GraphView.get_vertex_filter")
() | Return the vertex filter property. |
| [`get_vertices`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_vertices "graph_tool.GraphView.get_vertices")
(\[vprops\]) | Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the vertex indices, and optional vertex properties list `vprops`. |
| [`is_directed`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.is_directed "graph_tool.GraphView.is_directed")
() | Get the directedness of the graph. |
| [`is_reversed`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.is_reversed "graph_tool.GraphView.is_reversed")
() | Return `True` if the edges are reversed, and `False` otherwise. |
| [`iter_all_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_all_edges "graph_tool.GraphView.iter_all_edges")
(v\[, eprops\]) | Return an iterator over the in- and out-edge `` `(source, target) `` pairs for vertex `v`, and optional edge properties list `eprops`. |
| [`iter_all_neighbors`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_all_neighbors "graph_tool.GraphView.iter_all_neighbors")
(v\[, vprops\]) | Return an iterator over the in- and out-neighbors of vertex `v`, and optional vertex properties list `vprops`. |
| [`iter_all_neighbours`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_all_neighbours "graph_tool.GraphView.iter_all_neighbours")
(v\[, vprops\]) | Return an iterator over the in- and out-neighbors of vertex `v`, and optional vertex properties list `vprops`. |
| [`iter_edge_range`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_edge_range "graph_tool.GraphView.iter_edge_range")
(s, t, eprops) | Return an iterator over the edge properties list `eprops` for parallel edges between vertices `s` and `t`. |
| [`iter_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_edges "graph_tool.GraphView.iter_edges")
(\[eprops\]) | Return an iterator over the edge `` `(source, target) `` pairs, and optional edge properties list `eprops`. |
| [`iter_in_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_in_edges "graph_tool.GraphView.iter_in_edges")
(v\[, eprops\]) | Return an iterator over the in-edge `` `(source, target) `` pairs for vertex `v`, and optional edge properties list `eprops`. |
| [`iter_in_neighbors`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_in_neighbors "graph_tool.GraphView.iter_in_neighbors")
(v\[, vprops\]) | Return an iterator over the in-neighbors of vertex `v`, and optional vertex properties list `vprops`. |
| [`iter_in_neighbours`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_in_neighbours "graph_tool.GraphView.iter_in_neighbours")
(v\[, vprops\]) | Return an iterator over the in-neighbors of vertex `v`, and optional vertex properties list `vprops`. |
| [`iter_out_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_out_edges "graph_tool.GraphView.iter_out_edges")
(v\[, eprops\]) | Return an iterator over the out-edge `` `(source, target) `` pairs for vertex `v`, and optional edge properties list `eprops`. |
| [`iter_out_neighbors`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_out_neighbors "graph_tool.GraphView.iter_out_neighbors")
(v\[, vprops\]) | Return an iterator over the out-neighbors of vertex `v`, and optional vertex properties list `vprops`. |
| [`iter_out_neighbours`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_out_neighbours "graph_tool.GraphView.iter_out_neighbours")
(v\[, vprops\]) | Return an iterator over the out-neighbors of vertex `v`, and optional vertex properties list `vprops`. |
| [`iter_vertices`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_vertices "graph_tool.GraphView.iter_vertices")
(\[vprops\]) | Return an iterator over the vertex indices, and optional vertex properties list `vprops`. |
| [`list_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.list_properties "graph_tool.GraphView.list_properties")
() | Print a list of all internal properties. |
| [`load`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.load "graph_tool.GraphView.load")
(file\_name\[, fmt, ignore\_vp, ignore\_ep, ...\]) | Load graph from `file_name` (which can be either a string or a file-like object). |
| [`new_edge_property`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_edge_property "graph_tool.GraphView.new_edge_property")
(value\_type\[, vals, val\]) | Create a new edge property map of type `value_type`, and return it. |
| [`new_ep`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_ep "graph_tool.GraphView.new_ep")
(value\_type\[, vals, val\]) | Alias to [`new_edge_property()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_edge_property "graph_tool.Graph.new_edge_property")
. |
| [`new_gp`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_gp "graph_tool.GraphView.new_gp")
(value\_type\[, val\]) | Alias to [`new_graph_property()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_graph_property "graph_tool.Graph.new_graph_property")
. |
| [`new_graph_property`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_graph_property "graph_tool.GraphView.new_graph_property")
(value\_type\[, val\]) | Create a new graph property map of type `value_type`, and return it. |
| [`new_property`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_property "graph_tool.GraphView.new_property")
(key\_type, value\_type\[, vals, val\]) | Create a new (uninitialized) vertex property map of key type `key_type` (`v`, `e` or `g`), value type `value_type`, and return it. |
| [`new_vertex_property`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_vertex_property "graph_tool.GraphView.new_vertex_property")
(value\_type\[, vals, val\]) | Create a new vertex property map of type `value_type`, and return it. |
| [`new_vp`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_vp "graph_tool.GraphView.new_vp")
(value\_type\[, vals, val\]) | Alias to [`new_vertex_property()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_vertex_property "graph_tool.Graph.new_vertex_property")
. |
| [`num_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.num_edges "graph_tool.GraphView.num_edges")
(\[ignore\_filter\]) | Get the number of edges. |
| [`num_vertices`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.num_vertices "graph_tool.GraphView.num_vertices")
(\[ignore\_filter\]) | Get the number of vertices. |
| [`own_property`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.own_property "graph_tool.GraphView.own_property")
(prop) | Return a version of the property map 'prop' (possibly belonging to another graph) which is owned by the current graph. |
| [`purge_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.purge_edges "graph_tool.GraphView.purge_edges")
() | Remove all edges of the graph which are currently being filtered out. |
| [`purge_vertices`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.purge_vertices "graph_tool.GraphView.purge_vertices")
(\[in\_place\]) | Remove all vertices of the graph which are currently being filtered out. |
| [`reindex_edges`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.reindex_edges "graph_tool.GraphView.reindex_edges")
() | Reset the edge indices so that they lie in the \[0, [`num_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.num_edges "graph_tool.Graph.num_edges")
- 1\] range. |
| [`remove_edge`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.remove_edge "graph_tool.GraphView.remove_edge")
(edge) | Remove an edge from the graph. |
| [`remove_vertex`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.remove_vertex "graph_tool.GraphView.remove_vertex")
(vertex\[, fast\]) | Remove a vertex from the graph. |
| [`save`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.save "graph_tool.GraphView.save")
(file\_name\[, fmt\]) | Save graph to `file_name` (which can be either a string or a file-like object). |
| [`set_directed`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_directed "graph_tool.GraphView.set_directed")
(is\_directed) | Set the directedness of the graph. |
| [`set_edge_filter`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_edge_filter "graph_tool.GraphView.set_edge_filter")
(prop) | Set the edge boolean filter property. |
| [`set_fast_edge_lookup`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_fast_edge_lookup "graph_tool.GraphView.set_fast_edge_lookup")
(\[fast\]) | If `fast == True` the fast \\(O(1)\\) lookup of edges will be enabled. |
| [`set_fast_edge_removal`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_fast_edge_removal "graph_tool.GraphView.set_fast_edge_removal")
(\[fast\]) | If `fast == True` the fast \\(O(1)\\) removal of edges will be enabled. |
| [`set_filter_state`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_filter_state "graph_tool.GraphView.set_filter_state")
(state) | Set the filter state of the graph. |
| [`set_filters`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_filters "graph_tool.GraphView.set_filters")
(eprop, vprop) | Set the boolean properties for edge and vertex filters, respectively. |
| [`set_reversed`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_reversed "graph_tool.GraphView.set_reversed")
(is\_reversed) | Reverse the direction of the edges, if `is_reversed` is `True`, or maintain the original direction otherwise. |
| [`set_vertex_filter`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_vertex_filter "graph_tool.GraphView.set_vertex_filter")
(prop) | Set the vertex boolean filter property. |
| [`shrink_to_fit`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.shrink_to_fit "graph_tool.GraphView.shrink_to_fit")
() | Force the physical capacity of the underlying containers to match the graph's actual size, potentially freeing memory back to the system. |
| [`vertex`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.vertex "graph_tool.GraphView.vertex")
(i\[, use\_index, add\_missing\]) | Return the vertex with index `i`. |
| [`vertices`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.vertices "graph_tool.GraphView.vertices")
() | Return an [`iterator`](https://docs.python.org/3/library/stdtypes.html#iterator.__iter__ "(in Python v3.13)")
over the vertices. |
Attributes
| | |
| --- | --- |
| [`base`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.base "graph_tool.GraphView.base") | Base graph. |
| [`edge_index`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.edge_index "graph_tool.GraphView.edge_index") | Edge index map. |
| [`edge_index_range`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.edge_index_range "graph_tool.GraphView.edge_index_range") | The size of the range of edge indices. |
| [`edge_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.edge_properties "graph_tool.GraphView.edge_properties") | Dictionary of internal edge properties. |
| [`ep`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.ep "graph_tool.GraphView.ep") | Alias to [`edge_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge_properties "graph_tool.Graph.edge_properties")
. |
| [`gp`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.gp "graph_tool.GraphView.gp") | Alias to [`graph_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.graph_properties "graph_tool.Graph.graph_properties")
. |
| [`graph_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.graph_properties "graph_tool.GraphView.graph_properties") | Dictionary of internal graph properties. |
| [`properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.properties "graph_tool.GraphView.properties") | Dictionary of internal properties. |
| [`vertex_index`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.vertex_index "graph_tool.GraphView.vertex_index") | Vertex index map. |
| [`vertex_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.vertex_properties "graph_tool.GraphView.vertex_properties") | Dictionary of internal vertex properties. |
| [`vp`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.vp "graph_tool.GraphView.vp") | Alias to [`vertex_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex_properties "graph_tool.Graph.vertex_properties")
. |
add\_edge(_source_, _target_, _add\_missing\=True_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.add_edge "Link to this definition")
Add a new edge from `source` to `target` to the graph, and return it. This operation is \\(O(1)\\).
If `add_missing == True`, the source and target vertices are included in the graph if they don’t yet exist.
add\_edge\_list(_edge\_list_, _hashed\=False_, _hash\_type\='string'_, _eprops\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.add_edge_list "Link to this definition")
Add a list of edges to the graph, given by `edge_list`, which can be an iterator of `(source, target)` pairs where both `source` and `target` are vertex indices (or can be so converted), or a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
of shape `(E,2)`, where `E` is the number of edges, and each line specifies a `(source, target)` pair. If the list references vertices which do not exist in the graph, they will be created.
Optionally, if `hashed == True`, the vertex values in the edge list are not assumed to correspond to vertex indices directly. In this case they will be mapped to vertex indices according to the order in which they are encountered, and a vertex property map with the vertex values is returned. The option `hash_type` will determine the expected type used by the hash keys, and they can be any property map value type (see [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
), unless `edge_list` is a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
, in which case the value of this option is ignored, and the type is determined automatically.
If `hashed == False` and the target value of an edge corresponds to the maximum interger value ([`sys.maxsize`](https://docs.python.org/3/library/sys.html#sys.maxsize "(in Python v3.13)")
, or the maximum integer type of the [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
object), or is a [`numpy.nan`](https://numpy.org/doc/stable/reference/constants.html#numpy.nan "(in NumPy v2.3)")
or [`numpy.inf`](https://numpy.org/doc/stable/reference/constants.html#numpy.inf "(in NumPy v2.3)")
value, then only the source vertex will be added to the graph.
If `hashed == True`, and the target value corresponds to `None`, then only the source vertex will be added to the graph.
If given, `eprops` should specify an iterable containing edge property maps that will be filled with the remaining values at each row, if there are more than two. Alternatively, `eprops` can contain a list of `(name, value_type)` pairs, in which case new internal dege property maps will be created with the corresponding name name and value type.
Note
If `edge_list` is a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
object, the execution of this function will be done entirely in C++, and hence much faster.
Examples
\>>> edge\_list \= \[(0, 1, .3, 10), (2, 3, .1, 0), (2, 0, .4, 42)\]
\>>> g \= gt.Graph()
\>>> eweight \= g.new\_ep("double")
\>>> elayer \= g.new\_ep("int")
\>>> g.add\_edge\_list(edge\_list, eprops\=\[eweight, elayer\])
\>>> print(eweight.fa)
\[0.3 0.1 0.4\]
\>>> g.get\_edges()
array(\[\[0, 1\],\
\[2, 3\],\
\[2, 0\]\])
add\_vertex(_n\=1_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.add_vertex "Link to this definition")
Add a vertex to the graph, and return it. If `n != 1`, `n` vertices are inserted and an iterator over the new vertices is returned. This operation is \\(O(n)\\).
clear()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.clear "Link to this definition")
Remove all vertices and edges from the graph.
clear\_edges()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.clear_edges "Link to this definition")
Remove all edges from the graph.
clear\_filters()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.clear_filters "Link to this definition")
Remove vertex and edge filters, and set the graph to the unfiltered state.
Note
This is a \\(O(1)\\) operation that does not modify the storage of the graph.
Warning
Clearing vertex and edge filters will invalidate existing vertex and edge descriptors.
clear\_vertex(_vertex_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.clear_vertex "Link to this definition")
Remove all in and out-edges from the given vertex.
copy()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.copy "Link to this definition")
Return a deep copy of self. All [internal property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-internal-props)
are also copied.
copy\_property(_src_, _tgt\=None_, _value\_type\=None_, _g\=None_, _full\=True_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.copy_property "Link to this definition")
Copy contents of `src` property to `tgt` property. If `tgt` is None, then a new property map of the same type (or with the type given by the optional `value_type` parameter) is created, and returned. The optional parameter `g` specifies the source graph to copy properties from (defaults to the graph than owns src). If `full == False`, then in the case of filtered graphs only the unmasked values are copied (with the remaining ones taking the type-dependent default value).
Note
In case the source property map belongs to different graphs, this function behaves as follows.
For vertex properties, the source and target graphs must have the same number of vertices, and the properties are copied according to the index values.
For edge properties, the edge index is not important, and the properties are copied by matching edges between the different graphs according to the source and target vertex indices. In case the graph has parallel edges with the same source and target vertices, they are matched according to their iteration order. The edge sets do not have to be the same between source and target graphs, as the copying occurs only for edges that lie at their intersection.
degree\_property\_map(_deg_, _weight\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.degree_property_map "Link to this definition")
Create and return a vertex property map containing the degree type given by `deg`, which can be any of `"in"`, `"out"`, or `"total"`. If provided, `weight` should be an edge [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
containing the edge weights which should be summed.
edge(_s_, _t_, _all\_edges\=False_, _add\_missing\=False_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.edge "Link to this definition")
Return the edge from vertex `s` to `t`, if it exists. If `all_edges=True` then a list is returned with all the parallel edges from `s` to `t`, otherwise only one edge is returned.
If `add_missing == True`, a new edge is created and returned, if none currently exists.
This operation normally will take \\(O(\\min(k(s), k(t)))\\) time, where \\(k(s)\\) and \\(k(t)\\) are the out-degree and in-degree (or out-degree if undirected) of vertices \\(s\\) and \\(t\\). However, if [`set_fast_edge_lookup()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_lookup "graph_tool.Graph.set_fast_edge_lookup")
is set to True, this operation becomes \\(O(1)\\).
edges()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.edges "Link to this definition")
Return an [`iterator`](https://docs.python.org/3/library/stdtypes.html#iterator.__iter__ "(in Python v3.13)")
over the edges.
Note
The order of the edges traversed by the iterator **does not** necessarily correspond to the edge index ordering, as given by the [`edge_index`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge_index "graph_tool.Graph.edge_index")
property map. This will only happen after [`reindex_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.reindex_edges "graph_tool.Graph.reindex_edges")
is called, or in certain situations such as just after a graph is loaded from a file. However, further manipulation of the graph may destroy the ordering.
get\_all\_edges(_v_, _eprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_all_edges "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in- and out-edges of vertex v, and optional edge properties list `eprops`. The shape of the array will be `(E, 2 + len(eprops))`, where `E` is the number of edges, and each line will contain the source, target and the edge property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_all\_edges(66, \[g.edge\_index\])
array(\[\[ 66, 63, 5266\],\
\[ 66, 20369, 5267\],\
\[ 66, 13980, 5268\],\
\[ 66, 8687, 5269\],\
\[ 66, 38674, 5270\],\
\[ 8687, 66, 179681\],\
\[ 20369, 66, 255033\],\
\[ 38674, 66, 300230\]\])
get\_all\_neighbors(_v_, _vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_all_neighbors "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-neighbors and out-neighbors of vertex `v`, and optional vertex properties list `vprops`. If `vprops` is not empty, the shape of the array will be `(V, 1 + len(eprops))`, where `V` is the number of vertices, and each line will contain a vertex and its property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_all\_neighbors(66)
array(\[ 63, 20369, 13980, 8687, 38674, 8687, 20369, 38674\])
get\_all\_neighbours(_v_, _vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_all_neighbours "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-neighbors and out-neighbors of vertex `v`, and optional vertex properties list `vprops`. If `vprops` is not empty, the shape of the array will be `(V, 1 + len(eprops))`, where `V` is the number of vertices, and each line will contain a vertex and its property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_all\_neighbors(66)
array(\[ 63, 20369, 13980, 8687, 38674, 8687, 20369, 38674\])
get\_edge\_filter()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_edge_filter "Link to this definition")
Return the edge filter property map.
get\_edge\_range(_s_, _t_, _eprops_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_edge_range "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the parallel edge properties `eprops` for the parallel edges between vertices `s` and `t`.
The shape of the array will be `(m, len(eprops))`, where `m` is the number of parallele edges, and each line will contain the edge property values.
This operation normally will take \\(O(\\times\\min(k(s), k(t)))\\) time, where \\(k(s)\\) and \\(k(t)\\) are the out-degree and in-degree (or out-degree if undirected) of vertices \\(s\\) and \\(t\\). However, if [`set_fast_edge_lookup()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_lookup "graph_tool.Graph.set_fast_edge_lookup")
is set to True, this operation becomes \\(O(m)\\), where \\(m\\) being the number of parallel edges.
Note
The order of the edges is identical to [`edge()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge "graph_tool.Graph.edge")
.
Examples
\>>> g \= gt.Graph(\[(0, 1), (0, 1)\])
\>>> g.get\_edge\_range(0, 1, \[g.edge\_index\])
array(\[\[0\],\
\[1\]\])
get\_edges(_eprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_edges "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the edges, and optional edge properties list `eprops`. The shape of the array will be `(E, 2 + len(eprops))`, where `E` is the number of edges, and each line will contain the source, target and the edge property values.
Note
The order of the edges is identical to [`edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edges "graph_tool.Graph.edges")
.
Examples
\>>> g \= gt.random\_graph(6, lambda: 1, directed\=False)
\>>> g.get\_edges(\[g.edge\_index\])
array(\[\[3, 2, 0\],\
\[4, 1, 2\],\
\[5, 0, 1\]\])
get\_fast\_edge\_lookup()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_fast_edge_lookup "Link to this definition")
Return whether the fast \\(O(1)\\) lookup of edges is currently enabled.
get\_fast\_edge\_removal()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_fast_edge_removal "Link to this definition")
Return whether the fast \\(O(1)\\) removal of edges is currently enabled.
get\_filter\_state()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_filter_state "Link to this definition")
Return a copy of the filter state of the graph.
get\_in\_degrees(_vs_, _eweight\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_in_degrees "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-degrees of vertex list `vs`. If supplied, the degrees will be weighted according to the edge [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
`eweight`.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_in\_degrees(\[42, 666\])
array(\[20, 39\], dtype=uint64)
get\_in\_edges(_v_, _eprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_in_edges "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-edges of vertex `v`, and optional edge properties list `eprops`. The shape of the array will be `(E, 2 + len(eprops))`, where `E` is the number of edges, and each line will contain the source, target and the edge property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_in\_edges(66, \[g.edge\_index\])
array(\[\[ 8687, 66, 179681\],\
\[ 20369, 66, 255033\],\
\[ 38674, 66, 300230\]\])
get\_in\_neighbors(_v_, _vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_in_neighbors "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-neighbors of vertex `v`, and optional vertex properties list `vprops`. If `vprops` is not empty, the shape of the array will be `(V, 1 + len(eprops))`, where `V` is the number of vertices, and each line will contain a vertex and its property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_in\_neighbors(66)
array(\[ 8687, 20369, 38674\])
get\_in\_neighbours(_v_, _vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_in_neighbours "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the in-neighbors of vertex `v`, and optional vertex properties list `vprops`. If `vprops` is not empty, the shape of the array will be `(V, 1 + len(eprops))`, where `V` is the number of vertices, and each line will contain a vertex and its property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_in\_neighbors(66)
array(\[ 8687, 20369, 38674\])
get\_out\_degrees(_vs_, _eweight\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_out_degrees "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the out-degrees of vertex list `vs`. If supplied, the degrees will be weighted according to the edge [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
`eweight`.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_out\_degrees(\[42, 666\])
array(\[20, 38\], dtype=uint64)
get\_out\_edges(_v_, _eprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_out_edges "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the out-edges of vertex `v`, and optional edge properties list `eprops`. The shape of the array will be `(E, 2 + len(eprops))`, where `E` is the number of edges, and each line will contain the source, target and the edge property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_out\_edges(66, \[g.edge\_index\])
array(\[\[ 66, 63, 5266\],\
\[ 66, 20369, 5267\],\
\[ 66, 13980, 5268\],\
\[ 66, 8687, 5269\],\
\[ 66, 38674, 5270\]\])
get\_out\_neighbors(_v_, _vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_out_neighbors "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the out-neighbors of vertex `v`, and optional vertex properties list `vprops`. If `vprops` is not empty, the shape of the array will be `(V, 1 + len(eprops))`, where `V` is the number of vertices, and each line will contain a vertex and its property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_out\_neighbors(66)
array(\[ 63, 20369, 13980, 8687, 38674\])
get\_out\_neighbours(_v_, _vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_out_neighbours "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the out-neighbors of vertex `v`, and optional vertex properties list `vprops`. If `vprops` is not empty, the shape of the array will be `(V, 1 + len(eprops))`, where `V` is the number of vertices, and each line will contain a vertex and its property values.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_out\_neighbors(66)
array(\[ 63, 20369, 13980, 8687, 38674\])
get\_total\_degrees(_vs_, _eweight\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_total_degrees "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the total degrees (i.e. in- plus out-degree) of vertex list `vs`. If supplied, the degrees will be weighted according to the edge [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
`eweight`.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> g.get\_total\_degrees(\[42, 666\])
array(\[40, 77\], dtype=uint64)
get\_vertex\_filter()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_vertex_filter "Link to this definition")
Return the vertex filter property.
get\_vertices(_vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.get_vertices "Link to this definition")
Return a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
containing the vertex indices, and optional vertex properties list `vprops`. If `vprops` is not empty, the shape of the array will be `(V, 1 + len(vprops))`, where `V` is the number of vertices, and each line will contain the vertex and the vertex property values.
Note
The order of the vertices is identical to [`vertices()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertices "graph_tool.Graph.vertices")
.
Examples
\>>> g \= gt.Graph()
\>>> g.add\_vertex(5)
<...>
\>>> g.get\_vertices()
array(\[0, 1, 2, 3, 4\])
is\_directed()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.is_directed "Link to this definition")
Get the directedness of the graph.
is\_reversed()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.is_reversed "Link to this definition")
Return `True` if the edges are reversed, and `False` otherwise.
iter\_all\_edges(_v_, _eprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_all_edges "Link to this definition")
Return an iterator over the in- and out-edge `` `(source, target) `` pairs for vertex `v`, and optional edge properties list `eprops`.
Note
This mode of iteration is more efficient than using [`all_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.all_edges "graph_tool.Vertex.all_edges")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for s, t, i in g.iter\_all\_edges(66, \[g.edge\_index\]):
... print(s, t, i)
66 63 5266
66 20369 5267
66 13980 5268
66 8687 5269
66 38674 5270
8687 66 179681
20369 66 255033
38674 66 300230
iter\_all\_neighbors(_v_, _vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_all_neighbors "Link to this definition")
Return an iterator over the in- and out-neighbors of vertex `v`, and optional vertex properties list `vprops`.
Note
This mode of iteration is more efficient than using [`all_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.all_neighbors "graph_tool.Vertex.all_neighbors")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for u, i in g.iter\_all\_neighbors(66, \[g.vp.uid\]):
... print(u, i)
63 \['paul wilders '\]
20369 \['Zhen-Xjell '\]
13980 \['Hooman '\]
8687 \['H. Loeung (howe81) ', 'howe81 ', 'Howie L (howe81) '\]
38674 \['Howie L (howe81) '\]
8687 \['H. Loeung (howe81) ', 'howe81 ', 'Howie L (howe81) '\]
20369 \['Zhen-Xjell '\]
38674 \['Howie L (howe81) '\]
iter\_all\_neighbours(_v_, _vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_all_neighbours "Link to this definition")
Return an iterator over the in- and out-neighbors of vertex `v`, and optional vertex properties list `vprops`.
Note
This mode of iteration is more efficient than using [`all_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.all_neighbors "graph_tool.Vertex.all_neighbors")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for u, i in g.iter\_all\_neighbors(66, \[g.vp.uid\]):
... print(u, i)
63 \['paul wilders '\]
20369 \['Zhen-Xjell '\]
13980 \['Hooman '\]
8687 \['H. Loeung (howe81) ', 'howe81 ', 'Howie L (howe81) '\]
38674 \['Howie L (howe81) '\]
8687 \['H. Loeung (howe81) ', 'howe81 ', 'Howie L (howe81) '\]
20369 \['Zhen-Xjell '\]
38674 \['Howie L (howe81) '\]
iter\_edge\_range(_s_, _t_, _eprops_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_edge_range "Link to this definition")
Return an iterator over the edge properties list `eprops` for parallel edges between vertices `s` and `t`.
This operation normally will take \\(O(\\times\\min(k(s), k(t)))\\) time, where \\(k(s)\\) and \\(k(t)\\) are the out-degree and in-degree (or out-degree if undirected) of vertices \\(s\\) and \\(t\\). However, if [`set_fast_edge_lookup()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_lookup "graph_tool.Graph.set_fast_edge_lookup")
is set to True, this operation becomes \\(O(m)\\), where \\(m\\) being the number of parallel edges.
Note
This mode of iteration is more efficient than using [`edge()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge "graph_tool.Graph.edge")
, as descriptor objects are not created.
Examples
\>>> g \= gt.Graph(\[(0, 1), (0, 1)\])
\>>> for i in g.iter\_edge\_range(0, 1, \[g.edge\_index\]):
... print(i)
\[0\]
\[1\]
iter\_edges(_eprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_edges "Link to this definition")
Return an iterator over the edge `` `(source, target) `` pairs, and optional edge properties list `eprops`.
Note
This mode of iteration is more efficient than using [`edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edges "graph_tool.Graph.edges")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["karate"\]
\>>> for s, t, i in g.iter\_edges(\[g.edge\_index\]):
... print(s, t, i)
... if s \== 5:
... break
1 0 0
2 0 1
2 1 2
3 0 3
3 1 4
3 2 5
4 0 6
5 0 7
iter\_in\_edges(_v_, _eprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_in_edges "Link to this definition")
Return an iterator over the in-edge `` `(source, target) `` pairs for vertex `v`, and optional edge properties list `eprops`.
Note
This mode of iteration is more efficient than using [`in_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_edges "graph_tool.Vertex.in_edges")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for s, t, i in g.iter\_in\_edges(66, \[g.edge\_index\]):
... print(s, t, i)
8687 66 179681
20369 66 255033
38674 66 300230
iter\_in\_neighbors(_v_, _vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_in_neighbors "Link to this definition")
Return an iterator over the in-neighbors of vertex `v`, and optional vertex properties list `vprops`.
Note
This mode of iteration is more efficient than using [`in_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_neighbors "graph_tool.Vertex.in_neighbors")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for u, i in g.iter\_in\_neighbors(66, \[g.vp.uid\]):
... print(u, i)
8687 \['H. Loeung (howe81) ', 'howe81 ', 'Howie L (howe81) '\]
20369 \['Zhen-Xjell '\]
38674 \['Howie L (howe81) '\]
iter\_in\_neighbours(_v_, _vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_in_neighbours "Link to this definition")
Return an iterator over the in-neighbors of vertex `v`, and optional vertex properties list `vprops`.
Note
This mode of iteration is more efficient than using [`in_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.in_neighbors "graph_tool.Vertex.in_neighbors")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for u, i in g.iter\_in\_neighbors(66, \[g.vp.uid\]):
... print(u, i)
8687 \['H. Loeung (howe81) ', 'howe81 ', 'Howie L (howe81) '\]
20369 \['Zhen-Xjell '\]
38674 \['Howie L (howe81) '\]
iter\_out\_edges(_v_, _eprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_out_edges "Link to this definition")
Return an iterator over the out-edge `` `(source, target) `` pairs for vertex `v`, and optional edge properties list `eprops`.
Note
This mode of iteration is more efficient than using [`out_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_edges "graph_tool.Vertex.out_edges")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for s, t, i in g.iter\_out\_edges(66, \[g.edge\_index\]):
... print(s, t, i)
66 63 5266
66 20369 5267
66 13980 5268
66 8687 5269
66 38674 5270
iter\_out\_neighbors(_v_, _vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_out_neighbors "Link to this definition")
Return an iterator over the out-neighbors of vertex `v`, and optional vertex properties list `vprops`.
Note
This mode of iteration is more efficient than using [`out_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_neighbors "graph_tool.Vertex.out_neighbors")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for u, i in g.iter\_out\_neighbors(66, \[g.vp.uid\]):
... print(u, i)
63 \['paul wilders '\]
20369 \['Zhen-Xjell '\]
13980 \['Hooman '\]
8687 \['H. Loeung (howe81) ', 'howe81 ', 'Howie L (howe81) '\]
38674 \['Howie L (howe81) '\]
iter\_out\_neighbours(_v_, _vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_out_neighbours "Link to this definition")
Return an iterator over the out-neighbors of vertex `v`, and optional vertex properties list `vprops`.
Note
This mode of iteration is more efficient than using [`out_neighbors()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex.out_neighbors "graph_tool.Vertex.out_neighbors")
, as descriptor objects are not created.
Examples
\>>> g \= gt.collection.data\["pgp-strong-2009"\]
\>>> for u, i in g.iter\_out\_neighbors(66, \[g.vp.uid\]):
... print(u, i)
63 \['paul wilders '\]
20369 \['Zhen-Xjell '\]
13980 \['Hooman '\]
8687 \['H. Loeung (howe81) ', 'howe81 ', 'Howie L (howe81) '\]
38674 \['Howie L (howe81) '\]
iter\_vertices(_vprops\=\[\]_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.iter_vertices "Link to this definition")
Return an iterator over the vertex indices, and optional vertex properties list `vprops`.
Note
This mode of iteration is more efficient than using [`vertices()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertices "graph_tool.Graph.vertices")
, as descriptor objects are not created.
Examples
\>>> g \= gt.Graph()
\>>> g.add\_vertex(5)
<...>
\>>> for v in g.iter\_vertices():
... print(v)
0
1
2
3
4
list\_properties()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.list_properties "Link to this definition")
Print a list of all internal properties.
Examples
\>>> g \= gt.Graph()
\>>> g.properties\[("e", "foo")\] \= g.new\_edge\_property("vector")
\>>> g.vertex\_properties\["foo"\] \= g.new\_vertex\_property("double")
\>>> g.vertex\_properties\["bar"\] \= g.new\_vertex\_property("python::object")
\>>> g.graph\_properties\["gnat"\] \= g.new\_graph\_property("string", "hi there!")
\>>> g.list\_properties()
gnat (graph) (type: string, val: hi there!)
bar (vertex) (type: python::object)
foo (vertex) (type: double)
foo (edge) (type: vector)
load(_file\_name_, _fmt\='auto'_, _ignore\_vp\=None_, _ignore\_ep\=None_, _ignore\_gp\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.load "Link to this definition")
Load graph from `file_name` (which can be either a string or a file-like object). The format is guessed from `file_name`, or can be specified by `fmt`, which can be either “gt”, “graphml”, “xml”, “dot” or “gml”. (Note that “graphml” and “xml” are synonyms).
If provided, the parameters `ignore_vp`, `ignore_ep` and `ignore_gp`, should contain a list of property names (vertex, edge or graph, respectively) which should be ignored when reading the file.
Warning
The only file formats which are capable of perfectly preserving the internal property maps are “gt” and “graphml”. Because of this, they should be preferred over the other formats whenever possible.
new\_edge\_property(_value\_type_, _vals\=None_, _val\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_edge_property "Link to this definition")
Create a new edge property map of type `value_type`, and return it. If provided, the values will be initialized by `vals`, which should be sequence or by `val` which should be a single value.
new\_ep(_value\_type_, _vals\=None_, _val\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_ep "Link to this definition")
Alias to [`new_edge_property()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_edge_property "graph_tool.Graph.new_edge_property")
.
new\_gp(_value\_type_, _val\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_gp "Link to this definition")
Alias to [`new_graph_property()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_graph_property "graph_tool.Graph.new_graph_property")
.
new\_graph\_property(_value\_type_, _val\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_graph_property "Link to this definition")
Create a new graph property map of type `value_type`, and return it. If `val` is not None, the property is initialized to its value.
new\_property(_key\_type_, _value\_type_, _vals\=None_, _val\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_property "Link to this definition")
Create a new (uninitialized) vertex property map of key type `key_type` (`v`, `e` or `g`), value type `value_type`, and return it. If provided, the values will be initialized by `vals`, which should be a sequence, or by `val` which should be a single value.
new\_vertex\_property(_value\_type_, _vals\=None_, _val\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_vertex_property "Link to this definition")
Create a new vertex property map of type `value_type`, and return it. If provided, the values will be initialized by `vals`, which should be sequence or by `val` which should be a single value.
new\_vp(_value\_type_, _vals\=None_, _val\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.new_vp "Link to this definition")
Alias to [`new_vertex_property()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.new_vertex_property "graph_tool.Graph.new_vertex_property")
.
num\_edges(_ignore\_filter\=False_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.num_edges "Link to this definition")
Get the number of edges.
If `ignore_filter == True`, edge filters are ignored.
Note
If the edges are being filtered, and `ignore_filter == False`, this operation is \\(O(E)\\). Otherwise it is \\(O(1)\\).
num\_vertices(_ignore\_filter\=False_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.num_vertices "Link to this definition")
Get the number of vertices.
If `ignore_filter == True`, vertex filters are ignored.
Note
If the vertices are being filtered, and `ignore_filter == False`, this operation is \\(O(V)\\). Otherwise it is \\(O(1)\\).
own\_property(_prop_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.own_property "Link to this definition")
Return a version of the property map ‘prop’ (possibly belonging to another graph) which is owned by the current graph.
purge\_edges()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.purge_edges "Link to this definition")
Remove all edges of the graph which are currently being filtered out. This operation is not reversible.
purge\_vertices(_in\_place\=False_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.purge_vertices "Link to this definition")
Remove all vertices of the graph which are currently being filtered out. This operation is not reversible.
If the option `in_place == True` is given, the algorithm will remove the filtered vertices and re-index all property maps which are tied with the graph. This is a slow operation which has an \\(O(V^2)\\) complexity.
If `in_place == False`, the graph and its vertex and edge property maps are temporarily copied to a new unfiltered graph, which will replace the contents of the original graph. This is a fast operation with an \\(O(V + E)\\) complexity. This is the default behaviour if no option is given.
reindex\_edges()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.reindex_edges "Link to this definition")
Reset the edge indices so that they lie in the \[0, [`num_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.num_edges "graph_tool.Graph.num_edges")\
- 1\] range. The index ordering will be compatible with the sequence returned by the [`edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edges "graph_tool.Graph.edges")
function.
Warning
Calling this function will invalidate all existing edge property maps, if the index ordering is modified! The property maps will still be usable, but their contents will still be tied to the old indices, and thus may become scrambled.
remove\_edge(_edge_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.remove_edge "Link to this definition")
Remove an edge from the graph.
Note
This operation is normally \\(O(k\_s + k\_t)\\), where \\(k\_s\\) and \\(k\_t\\) are the total degrees of the source and target vertices, respectively. However, if [`set_fast_edge_removal()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_removal "graph_tool.Graph.set_fast_edge_removal")
is set to True, this operation becomes \\(O(1)\\).
Warning
The relative ordering of the remaining edges in the graph is kept unchanged, unless [`set_fast_edge_removal()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.set_fast_edge_removal "graph_tool.Graph.set_fast_edge_removal")
is set to True, in which case it can change.
remove\_vertex(_vertex_, _fast\=False_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.remove_vertex "Link to this definition")
Remove a vertex from the graph. If `vertex` is an iterable, it should correspond to a sequence of vertices to be removed.
Note
If the option `fast == False` is given, this operation is \\(O(V + E)\\) (this is the default). Otherwise it is \\(O(k + k\_{\\text{last}})\\), where \\(k\\) is the (total) degree of the vertex being deleted, and \\(k\_{\\text{last}}\\) is the (total) degree of the vertex with the largest index.
Warning
This operation may invalidate vertex descriptors. Vertices are always indexed contiguously in the range \\(\[0, N-1\]\\), hence vertex descriptors with an index higher than `vertex` will be invalidated after removal (if `fast == False`, otherwise only descriptors pointing to vertices with the largest index will be invalidated).
Because of this, the only safe way to remove more than one vertex at once is to sort them in decreasing index order:
\# 'del\_list' is a list of vertex descriptors
for v in reversed(sorted(del\_list)):
g.remove\_vertex(v)
Alternatively (and preferably), a list (or iterable) may be passed directly as the `vertex` parameter, and the above is performed internally (in C++).
Warning
If `fast == True`, the vertex being deleted is ‘swapped’ with the last vertex (i.e. with the largest index), which will in turn inherit the index of the vertex being deleted. All property maps associated with the graph will be properly updated, but the index ordering of the graph will no longer be the same.
save(_file\_name_, _fmt\='auto'_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.save "Link to this definition")
Save graph to `file_name` (which can be either a string or a file-like object). The format is guessed from the `file_name`, or can be specified by `fmt`, which can be either “gt”, “graphml”, “xml”, “dot” or “gml”. (Note that “graphml” and “xml” are synonyms).
Warning
The only file formats which are capable of perfectly preserving the internal property maps are “gt” and “graphml”. Because of this, they should be preferred over the other formats whenever possible.
set\_directed(_is\_directed_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_directed "Link to this definition")
Set the directedness of the graph.
Note
This is a \\(O(1)\\) operation that does not modify the storage of the graph.
Warning
Changing directedness will invalidate existing vertex and edge descriptors, which will still point to the original graph.
set\_edge\_filter(_prop_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_edge_filter "Link to this definition")
Set the edge boolean filter property. Only the edges with value different than `False` are kept in the filtered graph. If the supplied property is `None`, the filter is replaced by an uniform filter allowing all edges.
Note
This is a \\(O(1)\\) operation that does not modify the storage of the graph.
Warning
Setting edge filters will invalidate existing vertex and edge descriptors, which will still point to the unfiltered graph.
set\_fast\_edge\_lookup(_fast\=True_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_fast_edge_lookup "Link to this definition")
If `fast == True` the fast \\(O(1)\\) lookup of edges will be enabled. This requires an additional data structure of size \\(O(E)\\) to be kept at all times. If `fast == False`, this data structure is destroyed.
set\_fast\_edge\_removal(_fast\=True_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_fast_edge_removal "Link to this definition")
If `fast == True` the fast \\(O(1)\\) removal of edges will be enabled. This requires an additional data structure of size \\(O(E)\\) to be kept at all times. If `fast == False`, this data structure is destroyed.
set\_filter\_state(_state_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_filter_state "Link to this definition")
Set the filter state of the graph.
set\_filters(_eprop_, _vprop_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_filters "Link to this definition")
Set the boolean properties for edge and vertex filters, respectively. Only the vertices and edges with value different than `False` are kept in the filtered graph. If any of the supplied properties is `None`, an empty filter is constructed which allows all edges or vertices.
Note
This is a \\(O(1)\\) operation that does not modify the storage of the graph.
Warning
Setting vertex or edge filters will invalidate existing vertex and edge descriptors, which will still point to the unfiltered graph.
set\_reversed(_is\_reversed_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_reversed "Link to this definition")
Reverse the direction of the edges, if `is_reversed` is `True`, or maintain the original direction otherwise.
Note
This is a \\(O(1)\\) operation that does not modify the storage of the graph.
Warning
Reversing the graph will invalidate existing vertex and edge descriptors, which will still point to the original graph.
set\_vertex\_filter(_prop_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.set_vertex_filter "Link to this definition")
Set the vertex boolean filter property. Only the vertices with value different than `False` are kept in the filtered graph. If the supplied property is `None`, the filter is replaced by an uniform filter allowing all vertices.
Note
This is a \\(O(1)\\) operation that does not modify the storage of the graph.
Warning
Setting vertex filters will invalidate existing vertex and edge descriptors, which will still point to the unfiltered graph.
shrink\_to\_fit()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.shrink_to_fit "Link to this definition")
Force the physical capacity of the underlying containers to match the graph’s actual size, potentially freeing memory back to the system.
vertex(_i_, _use\_index\=True_, _add\_missing\=False_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.vertex "Link to this definition")
Return the vertex with index `i`. If `use_index=False`, the `i`\-th vertex is returned (which can differ from the vertex with index `i` in case of filtered graphs).
If `add_missing == True`, and the vertex does not exist in the graph, the necessary number of missing vertices are inserted, and the new vertex is returned.
vertices()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.vertices "Link to this definition")
Return an [`iterator`](https://docs.python.org/3/library/stdtypes.html#iterator.__iter__ "(in Python v3.13)")
over the vertices.
Note
The order of the vertices traversed by the iterator **always** corresponds to the vertex index ordering, as given by the [`vertex_index`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex_index "graph_tool.Graph.vertex_index")
property map.
Examples
\>>> g \= gt.Graph()
\>>> vlist \= list(g.add\_vertex(5))
\>>> vlist2 \= \[\]
\>>> for v in g.vertices():
... vlist2.append(v)
...
\>>> assert(vlist \== vlist2)
base[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.base "Link to this definition")
Base graph.
edge\_index[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.edge_index "Link to this definition")
Edge index map.
It maps for each edge in the graph an unique integer.
Note
Like [`vertex_index`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex_index "graph_tool.Graph.vertex_index")
, this is a special instance of a [`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
class, which is **immutable**, and cannot be accessed as an array.
Additionally, the indices may not necessarily lie in the range \[0, [`num_edges()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.num_edges "graph_tool.Graph.num_edges")\
- 1\]. However this will always happen whenever no edges are deleted from the graph.
edge\_index\_range[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.edge_index_range "Link to this definition")
The size of the range of edge indices.
edge\_properties[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.edge_properties "Link to this definition")
Dictionary of internal edge properties. The keys are the property names.
ep[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.ep "Link to this definition")
Alias to [`edge_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge_properties "graph_tool.Graph.edge_properties")
.
gp[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.gp "Link to this definition")
Alias to [`graph_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.graph_properties "graph_tool.Graph.graph_properties")
.
graph\_properties[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.graph_properties "Link to this definition")
Dictionary of internal graph properties. The keys are the property names.
properties[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.properties "Link to this definition")
Dictionary of internal properties. Keys must always be a tuple, where the first element if a string from the set `{'v', 'e', 'g'}`, representing a vertex, edge or graph property, respectively, and the second element is the name of the property map.
Examples
\>>> g \= gt.Graph()
\>>> g.properties\[("e", "foo")\] \= g.new\_edge\_property("vector")
\>>> del g.properties\[("e", "foo")\]
vertex\_index[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.vertex_index "Link to this definition")
Vertex index map.
It maps for each vertex in the graph an unique integer in the range \[0, [`num_vertices()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.num_vertices "graph_tool.Graph.num_vertices")\
- 1\].
Note
Like [`edge_index`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.edge_index "graph_tool.Graph.edge_index")
, this is a special instance of a [`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
class, which is **immutable**, and cannot be accessed as an array.
vertex\_properties[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.vertex_properties "Link to this definition")
Dictionary of internal vertex properties. The keys are the property names.
vp[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphView.html#graph_tool.GraphView.vp "Link to this definition")
Alias to [`vertex_properties`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph.vertex_properties "graph_tool.Graph.vertex_properties")
.
Contents
---
# GraphPropertyMap — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.GraphPropertyMap.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.GraphPropertyMap.rst "Download source file")
* .pdf
GraphPropertyMap
================
Contents
--------
GraphPropertyMap[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graphpropertymap "Link to this heading")
==========================================================================================================================================================
_class_ graph\_tool.GraphPropertyMap(_pmap_, _g_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#GraphPropertyMap)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap "Link to this definition")
Bases: [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
This class provides a mapping from graphs to arbitrary properties.
See [Property maps](https://graph-tool.skewed.de/static/docs/stable/quickstart.html#sec-property-maps)
and [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
for more details.
Methods
| | |
| --- | --- |
| [`coerce_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.coerce_type "graph_tool.GraphPropertyMap.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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.copy "graph_tool.GraphPropertyMap.copy")
(\[value\_type, full\]) | Return a copy of the property map. |
| [`data_ptr`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.data_ptr "graph_tool.GraphPropertyMap.data_ptr")
() | Return the pointer to memory where the data resides. |
| [`get_2d_array`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.get_2d_array "graph_tool.GraphPropertyMap.get_2d_array")
(\[pos, dtype\]) | 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, which contains a copy of all entries of the vector-valued property map. |
| [`get_array`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.get_array "graph_tool.GraphPropertyMap.get_array")
() | Get a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
subclass ([`PropertyArray`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "graph_tool.PropertyArray")
) pointint to the property values. |
| [`get_graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.get_graph "graph_tool.GraphPropertyMap.get_graph")
() | Get the graph class to which the map refers. |
| [`is_writable`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.is_writable "graph_tool.GraphPropertyMap.is_writable")
() | Return True if the property is writable. |
| [`key_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.key_type "graph_tool.GraphPropertyMap.key_type")
() | Return the key type of the map. |
| [`python_value_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.python_value_type "graph_tool.GraphPropertyMap.python_value_type")
() | Return the python-compatible value type of the map. |
| [`reserve`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.reserve "graph_tool.GraphPropertyMap.reserve")
(size) | Reserve enough space for `size` elements in underlying container. |
| [`resize`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.resize "graph_tool.GraphPropertyMap.resize")
(size) | Resize the underlying container to contain exactly `size` elements. |
| [`set_2d_array`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.set_2d_array "graph_tool.GraphPropertyMap.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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.set_value "graph_tool.GraphPropertyMap.set_value")
(val) | Sets all values in the property map to the same `val`. |
| [`set_values`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.set_values "graph_tool.GraphPropertyMap.set_values")
(vals) | Sets values in the property map to the iterable `vals`. |
| [`shrink_to_fit`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.shrink_to_fit "graph_tool.GraphPropertyMap.shrink_to_fit")
() | Shrink size of underlying container to accommodate only the necessary amount, and thus potentially freeing memory. |
| [`swap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.swap "graph_tool.GraphPropertyMap.swap")
(other) | Swap internal storage with `other`. |
| [`t`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.t "graph_tool.GraphPropertyMap.t")
(f\[, value\_type, no\_array, inplace\]) | Alias to [`transform()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.transform "graph_tool.PropertyMap.transform")
. |
| [`transform`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.transform "graph_tool.GraphPropertyMap.transform")
(f\[, value\_type, no\_array, inplace\]) | Return a copy of the property map with the values transformed by the user-supplied function `f`. |
| [`value_type`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.value_type "graph_tool.GraphPropertyMap.value_type")
() | Return the value type of the map. |
Attributes
| | |
| --- | --- |
| [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.a "graph_tool.GraphPropertyMap.a") | Shortcut to the [`get_array()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_array "graph_tool.PropertyMap.get_array")
method as an attribute. |
| [`fa`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.fa "graph_tool.GraphPropertyMap.fa") | The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, but instead an _indexed_ array is returned, which contains only entries for vertices/edges which are not filtered out. |
| [`ma`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.ma "graph_tool.GraphPropertyMap.ma") | The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, but instead a [`numpy.ma.MaskedArray`](https://numpy.org/doc/stable/reference/maskedarray.baseclass.html#numpy.ma.MaskedArray "(in NumPy v2.3)")
object is returned, which contains only entries for vertices/edges which are not filtered out. |
coerce\_type(_full\=True_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.coerce_type "Link to this definition")
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_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.copy "Link to this definition")
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()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.data_ptr "Link to this definition")
Return the pointer to memory where the data resides.
get\_2d\_array(_pos\=None_, _dtype\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.get_2d_array "Link to this definition")
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, which 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.
If `pos` is not given (the default), then it will be assumed to correspond to the entire range of the first entry in the map.
The parameter `dtype` determines the desired data-type for the array. If not given, it will be determined automatically (by applying promotion rules when necessary.)
get\_array()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.get_array "Link to this definition")
Get a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
subclass ([`PropertyArray`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "graph_tool.PropertyArray")
) pointint to 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()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_2d_array "graph_tool.PropertyMap.get_2d_array")
and [`set_2d_array()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.set_2d_array "graph_tool.PropertyMap.set_2d_array")
member functions.
Warning
This function does not copy the data from the property map, and therefore runs in \\(O(1)\\) time.
As a consequence, 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()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.get_graph "Link to this definition")
Get the graph class to which the map refers.
is\_writable()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.is_writable "Link to this definition")
Return True if the property is writable.
key\_type()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.key_type "Link to this definition")
Return the key type of the map. Either ‘g’, ‘v’ or ‘e’.
python\_value\_type()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.python_value_type "Link to this definition")
Return the python-compatible value type of the map.
reserve(_size_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.reserve "Link to this definition")
Reserve enough space for `size` elements in underlying container. If the original size is already equal or larger, nothing will happen.
resize(_size_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.resize "Link to this definition")
Resize the underlying container to contain exactly `size` elements.
set\_2d\_array(_a_, _pos\=None_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.set_2d_array "Link to this definition")
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_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.set_value "Link to this definition")
Sets all values in the property map to the same `val`.
set\_values(_vals_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.set_values "Link to this definition")
Sets values in the property map to the iterable `vals`.
shrink\_to\_fit()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.shrink_to_fit "Link to this definition")
Shrink size of underlying container to accommodate only the necessary amount, and thus potentially freeing memory.
swap(_other_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.swap "Link to this definition")
Swap internal storage with `other`.
t(_f_, _value\_type\=None_, _no\_array\=False_, _inplace\=False_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.t "Link to this definition")
Alias to [`transform()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.transform "graph_tool.PropertyMap.transform")
.
transform(_f_, _value\_type\=None_, _no\_array\=False_, _inplace\=False_)[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.transform "Link to this definition")
Return a copy of the property map with the values transformed by the user-supplied function `f`. If given, `value_type` specifies the value type for the new property map.
If the value type of the original map allows, the values will be passed to `f` as a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
, unless no\_array is `True`. Otherwise, they will be passed individually.
If `inplace == True` the transformation happens in-place, without copying the property map. In this case the parameter `value_type` is ignored.
value\_type()[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.value_type "Link to this definition")
Return the value type of the map.
a[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.a "Link to this definition")
Shortcut to the [`get_array()`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.get_array "graph_tool.PropertyMap.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[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.fa "Link to this definition")
The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute.
Warning
Because [advanced indexing](https://numpy.org/doc/stable/user/basics.indexing.html#advanced-indexing "(in NumPy v2.3)")
is triggered, a **copy** of the array is returned, not a view, as is the case for the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute. Nevertheless, the assignment of values to the _whole_ array at once works as expected.
Importantly, this means that this operation runs in time \\(O(N)\\) or O(N + E) for node and edge properties, respectively, where \\(N\\) is the number of vertices and \\(E\\) the number of edges in the unfiltered graph, and therefore can be significantly slower than using the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, which runs in time \\(O(1)\\).
ma[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.GraphPropertyMap.html#graph_tool.GraphPropertyMap.ma "Link to this definition")
The same as the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute, but instead a [`numpy.ma.MaskedArray`](https://numpy.org/doc/stable/reference/maskedarray.baseclass.html#numpy.ma.MaskedArray "(in NumPy v2.3)")
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`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "graph_tool.PropertyArray")
is returned, which is identical to the [`a`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.a "graph_tool.PropertyMap.a")
attribute.
Warning
Unlike [`fa`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap.fa "graph_tool.PropertyMap.fa")
, the masked array does _not_ copy the property map values.
This function runs in time \\(O(N)\\) or O(N + E) for node and edge properties, respectively, where \\(N\\) is the number of vertices and \\(E\\) the number of edges in the unfiltered graph.
Contents
---
# PropertyArray — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.PropertyArray.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.PropertyArray.rst "Download source file")
* .pdf
PropertyArray
=============
Contents
--------
PropertyArray[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#propertyarray "Link to this heading")
=================================================================================================================================================
_class_ graph\_tool.PropertyArray(_input\_array_, _prop\_map_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#PropertyArray)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray "Link to this definition")
Bases: [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
This is a [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
subclass which keeps a reference of its [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
owner.
Attributes
| | |
| --- | --- |
| [`prop_map`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray.prop_map "graph_tool.PropertyArray.prop_map") | [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
owner instance. |
prop\_map[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyArray.html#graph_tool.PropertyArray.prop_map "Link to this definition")
[`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
owner instance.
Contents
---
# ungroup_vector_property — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.ungroup_vector_property.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.ungroup_vector_property.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.ungroup_vector_property.rst "Download source file")
* .pdf
ungroup\_vector\_property
=========================
Contents
--------
ungroup\_vector\_property[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.ungroup_vector_property.html#ungroup-vector-property "Link to this heading")
=================================================================================================================================================================================
graph\_tool.ungroup\_vector\_property(_vprop_, _pos\=None_, _props\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#ungroup_vector_property)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.ungroup_vector_property.html#graph_tool.ungroup_vector_property "Link to this definition")
Ungroup vector property map `vprop` into a list of non-vector property maps.
Parameters:
**vprop**[`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
Vector property map to be ungrouped.
**pos**list of ints (optional, default: `None`)
A list of indices corresponding to where each element of `vprop` should be inserted into the ungrouped list. If not provided, it will correspond to the entire range of the first element in the map.
**props**list of [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
(optional, default: `None`)
If supplied, should contain a list of property maps to which `vprop` should be ungroupped.
Returns:
**props**list of [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
A list of property maps with the ungrouped values of `vprop`.
Examples
\>>> from numpy.random import seed, randint
\>>> from numpy import array
\>>> seed(42)
\>>> gt.seed\_rng(42)
\>>> g \= gt.random\_graph(100, lambda: (3, 3))
\>>> prop \= g.new\_vertex\_property("vector")
\>>> for v in g.vertices():
... prop\[v\] \= randint(0, 100, 3)
\>>> uprops \= gt.ungroup\_vector\_property(prop)
\>>> print(prop\[g.vertex(0)\].a)
\[51 92 14\]
\>>> print(array(\[p\[g.vertex(0)\] for p in uprops\]))
\[51 92 14\]
Contents
---
# group_vector_property — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.group_vector_property.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.group_vector_property.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.group_vector_property.rst "Download source file")
* .pdf
group\_vector\_property
=======================
Contents
--------
group\_vector\_property[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.group_vector_property.html#group-vector-property "Link to this heading")
===========================================================================================================================================================================
graph\_tool.group\_vector\_property(_props_, _value\_type\=None_, _vprop\=None_, _pos\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#group_vector_property)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.group_vector_property.html#graph_tool.group_vector_property "Link to this definition")
Group list of properties `props` into a vector property map of the same type.
Parameters:
**props**list of [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
Properties to be grouped.
**value\_type**string (optional, default: None)
If supplied, defines the value type of the grouped property.
**vprop**[`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
(optional, default: None)
If supplied, the properties are grouped into this property map.
**pos**list of ints (optional, default: None)
If supplied, should contain a list of indices where each corresponding element of `props` should be inserted.
Returns:
**vprop**[`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
A vector property map with the grouped values of each property map in `props`.
Examples
\>>> from numpy.random import seed, randint
\>>> from numpy import array
\>>> seed(42)
\>>> gt.seed\_rng(42)
\>>> g \= gt.random\_graph(100, lambda: (3, 3))
\>>> props \= \[g.new\_vertex\_property("int") for i in range(3)\]
\>>> for i in range(3):
... props\[i\].a \= randint(0, 100, g.num\_vertices())
\>>> gprop \= gt.group\_vector\_property(props)
\>>> print(gprop\[g.vertex(0)\].a)
\[51 25 8\]
\>>> print(array(\[p\[g.vertex(0)\] for p in props\]))
\[51 25 8\]
Contents
---
# edge_endpoint_property — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.edge_endpoint_property.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.edge_endpoint_property.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.edge_endpoint_property.rst "Download source file")
* .pdf
edge\_endpoint\_property
========================
Contents
--------
edge\_endpoint\_property[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.edge_endpoint_property.html#edge-endpoint-property "Link to this heading")
==============================================================================================================================================================================
graph\_tool.edge\_endpoint\_property(_g_, _prop_, _endpoint_, _eprop\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#edge_endpoint_property)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.edge_endpoint_property.html#graph_tool.edge_endpoint_property "Link to this definition")
Return an edge property map corresponding to the vertex property prop of either the target and source of the edge, according to endpoint.
Parameters:
**prop**[`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
Vertex property map to be used to propagated to the edge.
**endpoint**“source” or “target”
Edge endpoint considered. If the graph is undirected, the source is always the vertex with the lowest index.
**eprop**[`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
(optional, default: None)
If provided, the resulting edge properties will be stored here.
Returns:
**eprop**[`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
Propagated edge property.
Examples
\>>> gt.seed\_rng(42)
\>>> g \= gt.random\_graph(100, lambda: (3, 3))
\>>> esource \= gt.edge\_endpoint\_property(g, g.vertex\_index, "source")
\>>> print(esource.a)
\[55 29 10 31 41 19 53 45 18 97 58 83 3 1 95 76 15 74 43 68 43 57 2 0\
50 37 53 64 59 2 11 91 28 19 17 87 54 4 91 38 73 62 23 7 97 87 15 55\
8 50 82 30 58 93 77 6 96 15 47 68 8 8 14 71 86 81 74 98 33 57 21 77\
21 49 32 7 78 58 51 34 14 45 85 78 46 65 52 23 78 40 51 39 56 22 65 62\
71 3 24 10 63 60 72 60 20 28 92 49 88 70 84 13 21 26 65 47 59 80 3 99\
93 6 12 92 42 18 70 39 48 22 89 33 26 38 24 93 84 81 67 68 94 20 73 35\
25 51 57 88 52 6 86 70 36 62 95 83 22 89 54 24 37 43 13 94 5 48 81 44\
38 69 27 29 61 63 4 45 1 61 46 59 74 80 40 17 40 76 69 53 29 9 54 12\
72 12 82 72 11 0 44 94 17 90 79 14 86 26 71 79 19 35 61 9 56 73 52 23\
34 66 75 67 10 99 33 66 97 42 30 5 20 35 79 85 41 36 31 36 98 4 46 2\
82 27 30 47 49 91 1 84 13 98 85 7 99 77 64 90 0 95 31 90 67 88 55 27\
16 25 16 32 96 32 69 42 37 18 11 9 50 76 75 56 39 87 66 96 25 44 16 48\
75 89 63 41 64 34 5 28 60 80 83 92\]
Contents
---
# incident_edges_op — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.incident_edges_op.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.incident_edges_op.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.incident_edges_op.rst "Download source file")
* .pdf
incident\_edges\_op
===================
Contents
--------
incident\_edges\_op[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.incident_edges_op.html#incident-edges-op "Link to this heading")
===============================================================================================================================================================
graph\_tool.incident\_edges\_op(_g_, _direction_, _op_, _eprop_, _vprop\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#incident_edges_op)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.incident_edges_op.html#graph_tool.incident_edges_op "Link to this definition")
Return a vertex property map corresponding to a specific operation (sum, product, min or max) on the edge property eprop of incident edges on each vertex, following the direction given by direction.
Parameters:
**direction**“in” or “out”
Direction of the incident edges.
**op**“sum”, “prod”, “min” or “max”
Operation performed on incident edges.
**eprop**[`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
Edge property map to be summed.
**vprop**[`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
(optional, default: None)
If provided, the resulting vertex properties will be stored here.
Returns:
**vprop**[`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
Resulting vertex property.
Examples
\>>> gt.seed\_rng(42)
\>>> g \= gt.random\_graph(100, lambda: (3, 3))
\>>> vsum \= gt.incident\_edges\_op(g, "out", "sum", g.edge\_index)
\>>> print(vsum.a)
\[476 435 290 227 448 685 325 369 169 675 321 500 506 521 345 119 816 417\
406 246 473 254 378 344 391 693 450 674 432 360 519 495 610 421 588 581\
620 457 340 498 455 527 620 199 650 263 500 416 580 424 349 313 448 219\
384 309 583 236 139 323 500 559 289 563 573 293 722 617 217 625 386 365\
489 395 263 784 477 378 247 639 595 368 484 464 493 563 418 361 516 576\
715 314 528 308 502 425 607 277 552 592\]
Contents
---
# perfect_prop_hash — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.perfect_prop_hash.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.perfect_prop_hash.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.perfect_prop_hash.rst "Download source file")
* .pdf
perfect\_prop\_hash
===================
Contents
--------
perfect\_prop\_hash[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.perfect_prop_hash.html#perfect-prop-hash "Link to this heading")
===============================================================================================================================================================
graph\_tool.perfect\_prop\_hash(_props_, _htype\='int32\_t'_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#perfect_prop_hash)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.perfect_prop_hash.html#graph_tool.perfect_prop_hash "Link to this definition")
Given a list of property maps props of the same type, a derived list of property maps with integral type htype is returned, where each value is replaced by a perfect (i.e. unique) hash value.
Note
The hash value is deterministic, but it will not be necessarily the same for different values of props.
Contents
---
# map_property_values — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.map_property_values.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.map_property_values.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.map_property_values.rst "Download source file")
* .pdf
map\_property\_values
=====================
Contents
--------
map\_property\_values[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.map_property_values.html#map-property-values "Link to this heading")
=====================================================================================================================================================================
graph\_tool.map\_property\_values(_src\_prop_, _tgt\_prop_, _map\_func_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#map_property_values)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.map_property_values.html#graph_tool.map_property_values "Link to this definition")
Map the values of `src_prop` to `tgt_prop` according to the mapping function `map_func`.
Parameters:
**src\_prop**[`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
Source property map.
**tgt\_prop**[`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
Target property map.
**map\_func**function or callable object
Function mapping values of `src_prop` to values of `tgt_prop`.
Returns:
None
Examples
\>>> g \= gt.collection.data\["lesmis"\]
\>>> label\_len \= g.new\_vertex\_property("int64\_t")
\>>> gt.map\_property\_values(g.vp.label, label\_len,
... lambda x: len(x))
\>>> print(label\_len.a)
\[ 6 8 14 11 12 8 12 8 5 6 7 7 10 6 7 7 9 9 7 11 9 6 7 7\
13 10 7 6 12 10 8 8 11 6 5 12 6 10 11 9 12 7 7 6 14 7 9 9\
8 12 6 16 12 11 14 6 9 6 8 10 9 7 10 7 7 4 9 14 9 5 10 12\
9 6 6 6 12\]
Contents
---
# infect_vertex_property — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.infect_vertex_property.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.infect_vertex_property.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.infect_vertex_property.rst "Download source file")
* .pdf
infect\_vertex\_property
========================
Contents
--------
infect\_vertex\_property[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.infect_vertex_property.html#infect-vertex-property "Link to this heading")
==============================================================================================================================================================================
graph\_tool.infect\_vertex\_property(_g_, _prop_, _vals\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#infect_vertex_property)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.infect_vertex_property.html#graph_tool.infect_vertex_property "Link to this definition")
Propagate the prop values of vertices with value val to all their out-neighbors.
Parameters:
**prop**[`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
Property map to be modified.
**vals**list (optional, default: None)
List of values to be propagated. If not provided, all values will be propagated.
Returns:
**None**`None`
Examples
\>>> from numpy.random import seed
\>>> seed(42)
\>>> gt.seed\_rng(42)
\>>> g \= gt.random\_graph(100, lambda: (3, 3))
\>>> prop \= g.vertex\_index.copy("int32\_t")
\>>> gt.infect\_vertex\_property(g, prop, \[10\])
\>>> print(sum(prop.a \== 10))
4
Contents
---
# value_types — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.value_types.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.value_types.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.value_types.rst "Download source file")
* .pdf
value\_types
============
Contents
--------
value\_types[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.value_types.html#value-types "Link to this heading")
============================================================================================================================================
graph\_tool.value\_types()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#value_types)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.value_types.html#graph_tool.value_types "Link to this definition")
Return a list of possible properties value types.
Contents
---
# load_graph — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.load_graph.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.load_graph.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.load_graph.rst "Download source file")
* .pdf
load\_graph
===========
Contents
--------
load\_graph[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.load_graph.html#load-graph "Link to this heading")
=========================================================================================================================================
graph\_tool.load\_graph(_file\_name_, _fmt\='auto'_, _ignore\_vp\=None_, _ignore\_ep\=None_, _ignore\_gp\=None_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#load_graph)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.load_graph.html#graph_tool.load_graph "Link to this definition")
Load a graph from `file_name` (which can be either a string or a file-like object).
The format is guessed from `file_name`, or can be specified by `fmt`, which can be either “gt”, “graphml”, “xml”, “dot” or “gml”. (Note that “graphml” and “xml” are synonyms).
If provided, the parameters `ignore_vp`, `ignore_ep` and `ignore_gp`, should contain a list of property names (vertex, edge or graph, respectively) which should be ignored when reading the file.
Warning
The only file formats which are capable of perfectly preserving the internal property maps are “gt” and “graphml”. Because of this, they should be preferred over the other formats whenever possible.
Contents
---
# openmp_get_num_threads — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_num_threads.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.openmp_get_num_threads.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.openmp_get_num_threads.rst "Download source file")
* .pdf
openmp\_get\_num\_threads
=========================
Contents
--------
openmp\_get\_num\_threads[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_num_threads.html#openmp-get-num-threads "Link to this heading")
===============================================================================================================================================================================
graph\_tool.openmp\_get\_num\_threads()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_get_num_threads)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_num_threads.html#graph_tool.openmp_get_num_threads "Link to this definition")
Return the number of OpenMP threads.
Contents
---
# openmp_enabled — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_enabled.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.openmp_enabled.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.openmp_enabled.rst "Download source file")
* .pdf
openmp\_enabled
===============
Contents
--------
openmp\_enabled[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_enabled.html#openmp-enabled "Link to this heading")
=====================================================================================================================================================
graph\_tool.openmp\_enabled()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_enabled)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_enabled.html#graph_tool.openmp_enabled "Link to this definition")
Return `True` if OpenMP was enabled during compilation.
Contents
---
# openmp_set_num_threads — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_num_threads.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.openmp_set_num_threads.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.openmp_set_num_threads.rst "Download source file")
* .pdf
openmp\_set\_num\_threads
=========================
Contents
--------
openmp\_set\_num\_threads[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_num_threads.html#openmp-set-num-threads "Link to this heading")
===============================================================================================================================================================================
graph\_tool.openmp\_set\_num\_threads(_n_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_set_num_threads)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_num_threads.html#graph_tool.openmp_set_num_threads "Link to this definition")
Set the number of OpenMP threads.
Contents
---
# load_graph_from_csv — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.load_graph_from_csv.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.load_graph_from_csv.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.load_graph_from_csv.rst "Download source file")
* .pdf
load\_graph\_from\_csv
======================
Contents
--------
load\_graph\_from\_csv[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.load_graph_from_csv.html#load-graph-from-csv "Link to this heading")
======================================================================================================================================================================
graph\_tool.load\_graph\_from\_csv(_file\_name_, _directed\=False_, _eprop\_types\=None_, _eprop\_names\=None_, _hashed\=True_, _hash\_type\='string'_, _skip\_first\=False_, _strip\_whitespace\=True_, _ecols\=(0, 1)_, _csv\_options\={'delimiter': ',', 'quotechar': '"'}_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#load_graph_from_csv)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.load_graph_from_csv.html#graph_tool.load_graph_from_csv "Link to this definition")
Load a graph from a [`csv`](https://docs.python.org/3/library/csv.html#module-csv "(in Python v3.13)")
file containing a list of edges and edge properties.
Parameters:
**file\_name**`str` or file-like object
File in :mod:`csv` format, with edges given in each row.
**directed**`bool` (optional, default: `False`)
Whether or not the graph is directed.
**eprop\_types**list of `str` (optional, default: `None`)
List of edge property types to be read from remaining columns (if this is `None`, all properties will be of type `string`.
**eprop\_names**list of `str` (optional, default: `None`)
List of edge property names to be used for the remaining columns (if this is `None`, and `skip_first` is `True` their values will be obtained from the first line, otherwise they will be called `c1, c2, ...`).
**hashed**`bool` (optional, default: `True`)
If `True` the vertex values in the edge list are not assumed to correspond to vertex indices directly. In this case they will be mapped to vertex indices according to the order in which they are encountered, and a vertex property map with the vertex values is returned.
**hash\_type**`str` (optional, default: `string`)
If `hashed == True`, this will determined the type of the vertex values. It can be any property map value type (see [`PropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.PropertyMap.html#graph_tool.PropertyMap "graph_tool.PropertyMap")
).
**skip\_first**`bool` (optional, default: `False`)
If `True` the first line of the file will be skipped.
**strip\_whitespace**`bool` (optional, default: `True`)
If `True` whitespace will be striped from the start and end of values, before processing them.
**ecols**pair of `int` (optional, default: `(0,1)`)
Line columns used as source and target for the edges.
**csv\_options**`dict` (optional, default: `{"delimiter": ",", "quotechar": '"'}`)
Options to be passed to the [`csv.reader()`](https://docs.python.org/3/library/csv.html#csv.reader "(in Python v3.13)")
parser.
Returns:
**g**[`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
The loaded graph. It will contain additional columns in the file as internal edge property maps. If `hashed == True`, it will also contain an internal vertex property map with the vertex names.
Contents
---
# openmp_get_schedule — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_schedule.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.openmp_get_schedule.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.openmp_get_schedule.rst "Download source file")
* .pdf
openmp\_get\_schedule
=====================
Contents
--------
openmp\_get\_schedule[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_schedule.html#openmp-get-schedule "Link to this heading")
=====================================================================================================================================================================
graph\_tool.openmp\_get\_schedule()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_get_schedule)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_schedule.html#graph_tool.openmp_get_schedule "Link to this definition")
Return the runtime OpenMP schedule and chunk size. The schedule can by any of: `"static"`, `"dynamic"`, `"guided"`, `"auto"`.
Contents
---
# openmp_set_schedule — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_schedule.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.openmp_set_schedule.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.openmp_set_schedule.rst "Download source file")
* .pdf
openmp\_set\_schedule
=====================
Contents
--------
openmp\_set\_schedule[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_schedule.html#openmp-set-schedule "Link to this heading")
=====================================================================================================================================================================
graph\_tool.openmp\_set\_schedule(_schedule_, _chunk\=0_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_set_schedule)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_schedule.html#graph_tool.openmp_set_schedule "Link to this definition")
Set the runtime OpenMP schedule and chunk size. The schedule can by any of: `"static"`, `"dynamic"`, `"guided"`, `"auto"`.
Contents
---
# show_config — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.show_config.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.show_config.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.show_config.rst "Download source file")
* .pdf
show\_config
============
Contents
--------
show\_config[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.show_config.html#show-config "Link to this heading")
============================================================================================================================================
graph\_tool.show\_config()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool.html#show_config)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.show_config.html#graph_tool.show_config "Link to this definition")
Show `graph_tool` build configuration.
Contents
---
# openmp_get_thresh — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_thresh.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.openmp_get_thresh.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.openmp_get_thresh.rst "Download source file")
* .pdf
openmp\_get\_thresh
===================
Contents
--------
openmp\_get\_thresh[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_thresh.html#openmp-get-thresh "Link to this heading")
===============================================================================================================================================================
graph\_tool.openmp\_get\_thresh()[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_get_thresh)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_get_thresh.html#graph_tool.openmp_get_thresh "Link to this definition")
Return the minimum number of vertices necessary to enable parallelization.
Contents
---
# openmp_set_thresh — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_thresh.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.openmp_set_thresh.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.openmp_set_thresh.rst "Download source file")
* .pdf
openmp\_set\_thresh
===================
Contents
--------
openmp\_set\_thresh[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_thresh.html#openmp-set-thresh "Link to this heading")
===============================================================================================================================================================
graph\_tool.openmp\_set\_thresh(_n_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/openmp.html#openmp_set_thresh)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.openmp_set_thresh.html#graph_tool.openmp_set_thresh "Link to this definition")
Set the the minimum number of vertices necessary to enable parallelization.
Contents
---
# central_point_dominance — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.central_point_dominance.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.centrality.central_point_dominance.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.centrality.central_point_dominance.rst "Download source file")
* .pdf
central\_point\_dominance
=========================
Contents
--------
central\_point\_dominance[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.central_point_dominance.html#central-point-dominance "Link to this heading")
============================================================================================================================================================================================
graph\_tool.centrality.central\_point\_dominance(_g_, _betweenness_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/centrality.html#central_point_dominance)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.central_point_dominance.html#graph_tool.centrality.central_point_dominance "Link to this definition")
Calculate the central point dominance of the graph, given the betweenness centrality of each vertex.
Parameters:
**g**[`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
Graph to be used.
**betweenness**[`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
Vertex property map with the betweenness centrality values. The values must be normalized.
Returns:
**cp**float
The central point dominance.
See also
[`betweenness`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.betweenness.html#graph_tool.centrality.betweenness "graph_tool.centrality.betweenness")
betweenness centrality
Notes
Let \\(v^\*\\) be the vertex with the largest relative betweenness centrality; then, the central point dominance [\[freeman-set-1977\]](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.central_point_dominance.html#rfa00bd376865-freeman-set-1977)
is defined as:
\\\[C'\_B = \\frac{1}{|V|-1} \\sum\_{v} C\_B(v^\*) - C\_B(v)\\\]
where \\(C\_B(v)\\) is the normalized betweenness centrality of vertex v. The value of \\(C\_B\\) lies in the range \[0,1\].
The algorithm has a complexity of \\(O(V)\\).
References
\[[freeman-set-1977](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.central_point_dominance.html#id1)\
\]
Linton C. Freeman, “A Set of Measures of Centrality Based on Betweenness”, Sociometry, Vol. 40, No. 1, pp. 35-41, 1977, [DOI: 10.2307/3033543](https://dx.doi.org/10.2307/3033543)
\[[sci-hub](https://sci-hub.ru/10.2307/3033543)\
, [@tor](https://scihub22266oqcxt.onion/10.2307/3033543)\
\]
Examples
\>>> g \= gt.collection.data\["polblogs"\]
\>>> g \= gt.GraphView(g, vfilt\=gt.label\_largest\_component(g))
\>>> vp, ep \= gt.betweenness(g)
\>>> print(gt.central\_point\_dominance(g, vp))
0.218286...
Contents
---
# graph_tool.centrality — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/centrality.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/centrality.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/centrality.rst "Download source file")
* .pdf
graph\_tool.centrality
======================
Contents
--------
`graph_tool.centrality`[#](https://graph-tool.skewed.de/static/docs/stable/centrality.html#graph-tool-centrality "Link to this heading")
=========================================================================================================================================
This module provides centrality-related algorithms.
Summary[#](https://graph-tool.skewed.de/static/docs/stable/centrality.html#summary "Link to this heading")
-----------------------------------------------------------------------------------------------------------
| | |
| --- | --- |
| [`pagerank`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#graph_tool.centrality.pagerank "graph_tool.centrality.pagerank") | Calculate the PageRank of each vertex. |
| [`betweenness`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.betweenness.html#graph_tool.centrality.betweenness "graph_tool.centrality.betweenness") | Calculate the betweenness centrality for each vertex and edge. |
| [`central_point_dominance`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.central_point_dominance.html#graph_tool.centrality.central_point_dominance "graph_tool.centrality.central_point_dominance") | Calculate the central point dominance of the graph, given the betweenness centrality of each vertex. |
| [`closeness`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.closeness.html#graph_tool.centrality.closeness "graph_tool.centrality.closeness") | Calculate the closeness centrality for each vertex. |
| [`eigenvector`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.eigenvector.html#graph_tool.centrality.eigenvector "graph_tool.centrality.eigenvector") | Calculate the eigenvector centrality of each vertex in the graph, as well as the largest eigenvalue. |
| [`katz`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.katz.html#graph_tool.centrality.katz "graph_tool.centrality.katz") | Calculate the Katz centrality of each vertex in the graph. |
| [`hits`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.hits.html#graph_tool.centrality.hits "graph_tool.centrality.hits") | Calculate the authority and hub centralities of each vertex in the graph. |
| [`eigentrust`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.eigentrust.html#graph_tool.centrality.eigentrust "graph_tool.centrality.eigentrust") | Calculate the eigentrust centrality of each vertex in the graph. |
| [`trust_transitivity`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.trust_transitivity.html#graph_tool.centrality.trust_transitivity "graph_tool.centrality.trust_transitivity") | Calculate the pervasive trust transitivity between chosen (or all) vertices in the graph. |
Contents
---
# betweenness — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.betweenness.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.centrality.betweenness.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.centrality.betweenness.rst "Download source file")
* .pdf
betweenness
===========
Contents
--------
betweenness[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.betweenness.html#betweenness "Link to this heading")
======================================================================================================================================================
graph\_tool.centrality.betweenness(_g_, _pivots\=None_, _vprop\=None_, _eprop\=None_, _weight\=None_, _norm\=True_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/centrality.html#betweenness)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.betweenness.html#graph_tool.centrality.betweenness "Link to this definition")
Calculate the betweenness centrality for each vertex and edge.
Parameters:
**g**[`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
Graph to be used.
**pivots**list or [`numpy.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray "(in NumPy v2.3)")
, optional (default: None)
If provided, the betweenness will be estimated using the vertices in this list as pivots. If the list contains all nodes (the default) the algorithm will be exact, and if the vertices are randomly chosen the result will be an unbiased estimator.
**vprop**[`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
, optional (default: None)
Vertex property map to store the vertex betweenness values.
**eprop**[`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
, optional (default: None)
Edge property map to store the edge betweenness values.
**weight**[`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
, optional (default: None)
Edge property map corresponding to the weight value of each edge.
**norm**bool, optional (default: True)
Whether or not the betweenness values should be normalized.
Returns:
**vertex\_betweenness**A vertex property map with the vertex betweenness values.
**edge\_betweenness**An edge property map with the edge betweenness values.
See also
[`central_point_dominance`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.central_point_dominance.html#graph_tool.centrality.central_point_dominance "graph_tool.centrality.central_point_dominance")
central point dominance of the graph
[`pagerank`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#graph_tool.centrality.pagerank "graph_tool.centrality.pagerank")
PageRank centrality
[`eigentrust`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.eigentrust.html#graph_tool.centrality.eigentrust "graph_tool.centrality.eigentrust")
eigentrust centrality
[`eigenvector`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.eigenvector.html#graph_tool.centrality.eigenvector "graph_tool.centrality.eigenvector")
eigenvector centrality
[`hits`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.hits.html#graph_tool.centrality.hits "graph_tool.centrality.hits")
authority and hub centralities
[`trust_transitivity`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.trust_transitivity.html#graph_tool.centrality.trust_transitivity "graph_tool.centrality.trust_transitivity")
pervasive trust transitivity
Notes
Betweenness centrality of a vertex \\(C\_B(v)\\) is defined as,
\\\[C\_B(v)= \\sum\_{s \\neq v \\neq t \\in V \\atop s \\neq t} \\frac{\\sigma\_{st}(v)}{\\sigma\_{st}}\\\]
where \\(\\sigma\_{st}\\) is the number of shortest paths from s to t, and \\(\\sigma\_{st}(v)\\) is the number of shortest paths from s to t that pass through a vertex \\(v\\). This may be normalised by dividing through the number of pairs of vertices not including v, which is \\((n-1)(n-2)/2\\), for undirected graphs, or \\((n-1)(n-2)\\) for directed ones.
The algorithm used here is defined in [\[brandes-faster-2001\]](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.betweenness.html#re682384fa9d2-brandes-faster-2001)
, and has a complexity of \\(O(VE)\\) for unweighted graphs and \\(O(VE + V(V+E)\\log V)\\) for weighted graphs. The space complexity is \\(O(VE)\\).
If the `pivots` parameter is given, the complexity will be instead \\(O(PE)\\) for unweighted graphs and \\(O(PE + P(V+E)\\log V)\\) for weighted graphs, where \\(P\\) is the number of pivot vertices.
Parallel implementation.
If enabled during compilation, this algorithm will run in parallel using [OpenMP](https://en.wikipedia.org/wiki/OpenMP)
. See the [parallel algorithms](https://graph-tool.skewed.de/static/docs/stable/parallel.html#parallel-algorithms)
section for information about how to control several aspects of parallelization.
References
\[betweenness-wikipedia\]
[http://en.wikipedia.org/wiki/Centrality#Betweenness\_centrality](http://en.wikipedia.org/wiki/Centrality#Betweenness_centrality)
\[[brandes-faster-2001](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.betweenness.html#id1)\
\]
U. Brandes, “A faster algorithm for betweenness centrality”, Journal of Mathematical Sociology, 2001, [DOI: 10.1080/0022250X.2001.9990249](https://dx.doi.org/10.1080/0022250X.2001.9990249)
\[[sci-hub](https://sci-hub.ru/10.1080/0022250X.2001.9990249)\
, [@tor](https://scihub22266oqcxt.onion/10.1080/0022250X.2001.9990249)\
\]
\[brandes-centrality-2007\]
U. Brandes, C. Pich, “Centrality estimation in large networks”, Int. J. Bifurcation Chaos 17, 2303 (2007). [DOI: 10.1142/S0218127407018403](https://dx.doi.org/10.1142/S0218127407018403)
\[[sci-hub](https://sci-hub.ru/10.1142/S0218127407018403)\
, [@tor](https://scihub22266oqcxt.onion/10.1142/S0218127407018403)\
\]
\[[adamic-polblogs](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.betweenness.html#id6)\
\]
L. A. Adamic and N. Glance, “The political blogosphere and the 2004 US Election”, in Proceedings of the WWW-2005 Workshop on the Weblogging Ecosystem (2005). [DOI: 10.1145/1134271.1134277](https://dx.doi.org/10.1145/1134271.1134277)
\[[sci-hub](https://sci-hub.ru/10.1145/1134271.1134277)\
, [@tor](https://scihub22266oqcxt.onion/10.1145/1134271.1134277)\
\]
Examples
\>>> g \= gt.collection.data\["polblogs"\]
\>>> g \= gt.GraphView(g, vfilt\=gt.label\_largest\_component(g))
\>>> vp, ep \= gt.betweenness(g)
\>>> gt.graph\_draw(g, pos\=g.vp\["pos"\], vertex\_fill\_color\=vp,
... vertex\_size\=gt.prop\_to\_size(vp, mi\=5, ma\=15),
... edge\_pen\_width\=gt.prop\_to\_size(ep, mi\=0.5, ma\=5),
... vcmap\=matplotlib.cm.gist\_heat,
... vorder\=vp, output\="polblogs\_betweenness.pdf")
<...>
[](https://graph-tool.skewed.de/static/docs/stable/_images/polblogs_betweenness.png)
Betweenness values of the a political blogs network of [\[adamic-polblogs\]](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.betweenness.html#re682384fa9d2-adamic-polblogs)
.[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.betweenness.html#id7 "Link to this image")
Contents
---
# closeness — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.closeness.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.centrality.closeness.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.centrality.closeness.rst "Download source file")
* .pdf
closeness
=========
Contents
--------
closeness[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.closeness.html#closeness "Link to this heading")
================================================================================================================================================
graph\_tool.centrality.closeness(_g_, _weight\=None_, _source\=None_, _vprop\=None_, _norm\=True_, _harmonic\=False_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/centrality.html#closeness)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.closeness.html#graph_tool.centrality.closeness "Link to this definition")
Calculate the closeness centrality for each vertex.
Parameters:
**g**[`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
Graph to be used.
**weight**[`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
, optional (default: None)
Edge property map corresponding to the weight value of each edge.
**source**[`Vertex`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Vertex.html#graph_tool.Vertex "graph_tool.Vertex")
, optional (default: `None`)
If specified, the centrality is computed for this vertex alone.
**vprop**[`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
, optional (default: `None`)
Vertex property map to store the vertex centrality values.
**norm**bool, optional (default: `True`)
Whether or not the centrality values should be normalized.
**harmonic**bool, optional (default: `False`)
If true, the sum of the inverse of the distances will be computed, instead of the inverse of the sum.
Returns:
**vertex\_closeness**[`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
A vertex property map with the vertex closeness values.
See also
[`central_point_dominance`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.central_point_dominance.html#graph_tool.centrality.central_point_dominance "graph_tool.centrality.central_point_dominance")
central point dominance of the graph
[`pagerank`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#graph_tool.centrality.pagerank "graph_tool.centrality.pagerank")
PageRank centrality
[`eigentrust`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.eigentrust.html#graph_tool.centrality.eigentrust "graph_tool.centrality.eigentrust")
eigentrust centrality
[`eigenvector`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.eigenvector.html#graph_tool.centrality.eigenvector "graph_tool.centrality.eigenvector")
eigenvector centrality
[`hits`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.hits.html#graph_tool.centrality.hits "graph_tool.centrality.hits")
authority and hub centralities
[`trust_transitivity`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.trust_transitivity.html#graph_tool.centrality.trust_transitivity "graph_tool.centrality.trust_transitivity")
pervasive trust transitivity
Notes
The closeness centrality of a vertex \\(i\\) is defined as,
\\\[c\_i = \\frac{1}{\\sum\_j d\_{ij}}\\\]
where \\(d\_{ij}\\) is the (possibly directed and/or weighted) distance from \\(i\\) to \\(j\\). In case there is no path between the two vertices, here the distance is taken to be zero.
If `harmonic == True`, the definition becomes
\\\[c\_i = \\sum\_j\\frac{1}{d\_{ij}},\\\]
but now, in case there is no path between the two vertices, we take \\(d\_{ij} \\to\\infty\\) such that \\(1/d\_{ij}=0\\).
If `norm == True`, the values of \\(c\_i\\) are normalized by \\(n\_i-1\\) where \\(n\_i\\) is the size of the (out-) component of \\(i\\). If `harmonic == True`, they are instead simply normalized by \\(V-1\\).
The algorithm complexity of \\(O(V(V + E))\\) for unweighted graphs and \\(O(V(V+E) \\log V)\\) for weighted graphs. If the option `source` is specified, this drops to \\(O(V + E)\\) and \\(O((V+E)\\log V)\\) respectively.
Parallel implementation.
If enabled during compilation, this algorithm will run in parallel using [OpenMP](https://en.wikipedia.org/wiki/OpenMP)
. See the [parallel algorithms](https://graph-tool.skewed.de/static/docs/stable/parallel.html#parallel-algorithms)
section for information about how to control several aspects of parallelization.
References
\[closeness-wikipedia\]
[https://en.wikipedia.org/wiki/Closeness\_centrality](https://en.wikipedia.org/wiki/Closeness_centrality)
\[opsahl-node-2010\]
Opsahl, T., Agneessens, F., Skvoretz, J., “Node centrality in weighted networks: Generalizing degree and shortest paths”. Social Networks 32, 245-251, 2010 [DOI: 10.1016/j.socnet.2010.03.006](https://dx.doi.org/10.1016/j.socnet.2010.03.006)
\[[sci-hub](https://sci-hub.ru/10.1016/j.socnet.2010.03.006)\
, [@tor](https://scihub22266oqcxt.onion/10.1016/j.socnet.2010.03.006)\
\]
\[[adamic-polblogs](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.closeness.html#id4)\
\]
L. A. Adamic and N. Glance, “The political blogosphere and the 2004 US Election”, in Proceedings of the WWW-2005 Workshop on the Weblogging Ecosystem (2005). [DOI: 10.1145/1134271.1134277](https://dx.doi.org/10.1145/1134271.1134277)
\[[sci-hub](https://sci-hub.ru/10.1145/1134271.1134277)\
, [@tor](https://scihub22266oqcxt.onion/10.1145/1134271.1134277)\
\]
Examples
\>>> g \= gt.collection.data\["polblogs"\]
\>>> g \= gt.GraphView(g, vfilt\=gt.label\_largest\_component(g))
\>>> c \= gt.closeness(g)
\>>> gt.graph\_draw(g, pos\=g.vp\["pos"\], vertex\_fill\_color\=c,
... vertex\_size\=gt.prop\_to\_size(c, mi\=5, ma\=15),
... vcmap\=matplotlib.cm.gist\_heat,
... vorder\=c, output\="polblogs\_closeness.pdf")
<...>
[](https://graph-tool.skewed.de/static/docs/stable/_images/polblogs_closeness.png)
Closeness values of the a political blogs network of [\[adamic-polblogs\]](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.closeness.html#rcd7856f3f18e-adamic-polblogs)
.[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.closeness.html#id5 "Link to this image")
Contents
---
# pagerank — graph-tool 2.98 documentation
[Skip to main content](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#main-content)
Back to top Ctrl+K
[ \
\
graph-tool documentation \
(2.98)](https://graph-tool.skewed.de/static/docs/stable/index.html)
Choose version
* [GitLab](https://git.skewed.de/count0/graph-tool "GitLab")
* [Mastodon](https://social.skewed.de/@graph_tool "Mastodon")
* [Bluesky](https://bsky.app/profile/graph-tool.skewed.de "Bluesky")
* [Discourse](https://forum.skewed.de/c/graph-tool/5 "Discourse")
* [](https://graph-tool.skewed.de/ "graph-tool")
Search Ctrl+K
[](https://git.skewed.de/count0/graph-tool/-/edit/master//doc/autosummary/graph_tool.centrality.pagerank.rst "Suggest edit")
* [.rst](https://graph-tool.skewed.de/static/docs/stable/_sources/autosummary/graph_tool.centrality.pagerank.rst "Download source file")
* .pdf
pagerank
========
Contents
--------
pagerank[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#pagerank "Link to this heading")
=============================================================================================================================================
graph\_tool.centrality.pagerank(_g_, _damping\=0.85_, _pers\=None_, _weight\=None_, _prop\=None_, _epsilon\=1e-06_, _max\_iter\=None_, _ret\_iter\=False_)[\[source\]](https://graph-tool.skewed.de/static/docs/stable/_modules/graph_tool/centrality.html#pagerank)
[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#graph_tool.centrality.pagerank "Link to this definition")
Calculate the PageRank of each vertex.
Parameters:
**g**[`Graph`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.Graph.html#graph_tool.Graph "graph_tool.Graph")
Graph to be used.
**damping**float, optional (default: 0.85)
Damping factor.
**pers**[`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
, optional (default: None)
Personalization vector. If omitted, a constant value of \\(1/N\\) will be used.
**weight**[`EdgePropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.EdgePropertyMap.html#graph_tool.EdgePropertyMap "graph_tool.EdgePropertyMap")
, optional (default: None)
Edge weights. If omitted, a constant value of 1 will be used.
**prop**[`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
, optional (default: None)
Vertex property map to store the PageRank values. If supplied, it will be used uninitialized.
**epsilon**float, optional (default: 1e-6)
Convergence condition. The iteration will stop if the total delta of all vertices are below this value.
**max\_iter**int, optional (default: None)
If supplied, this will limit the total number of iterations.
**ret\_iter**bool, optional (default: False)
If true, the total number of iterations is also returned.
Returns:
**pagerank**[`VertexPropertyMap`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.VertexPropertyMap.html#graph_tool.VertexPropertyMap "graph_tool.VertexPropertyMap")
A vertex property map containing the PageRank values.
See also
[`betweenness`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.betweenness.html#graph_tool.centrality.betweenness "graph_tool.centrality.betweenness")
betweenness centrality
[`eigentrust`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.eigentrust.html#graph_tool.centrality.eigentrust "graph_tool.centrality.eigentrust")
eigentrust centrality
[`eigenvector`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.eigenvector.html#graph_tool.centrality.eigenvector "graph_tool.centrality.eigenvector")
eigenvector centrality
[`hits`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.hits.html#graph_tool.centrality.hits "graph_tool.centrality.hits")
authority and hub centralities
[`trust_transitivity`](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.trust_transitivity.html#graph_tool.centrality.trust_transitivity "graph_tool.centrality.trust_transitivity")
pervasive trust transitivity
Notes
The value of PageRank [\[pagerank-wikipedia\]](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#rb8d783549222-pagerank-wikipedia)
of vertex v, \\(PR(v)\\), is given iteratively by the relation:
\\\[PR(v) = \\frac{1-d}{N} + d \\sum\_{u \\in \\Gamma^{-}(v)} \\frac{PR (u)}{d^{+}(u)}\\\]
where \\(\\Gamma^{-}(v)\\) are the in-neighbors of v, \\(d^{+}(u)\\) is the out-degree of u, and d is a damping factor.
If a personalization property \\(p(v)\\) is given, the definition becomes:
\\\[PR(v) = (1-d)p(v) + d \\sum\_{u \\in \\Gamma^{-}(v)} \\frac{PR (u)}{d^{+}(u)}\\\]
If edge weights are also given, the equation is then generalized to:
\\\[PR(v) = (1-d)p(v) + d \\sum\_{u \\in \\Gamma^{-}(v)} \\frac{PR (u) w\_{u\\to v}}{d^{+}(u)}\\\]
where \\(d^{+}(u)=\\sum\_{y}A\_{u,y}w\_{u\\to y}\\) is redefined to be the sum of the weights of the out-going edges from u.
If a node has out-degree zero, it is assumed to connect to every other node with a weight proportional to \\(p(v)\\) or a constant if no personalization is given.
The implemented algorithm progressively iterates the above equations, until it no longer changes, according to the parameter epsilon. It has a topology-dependent running time.
Parallel implementation.
If enabled during compilation, this algorithm will run in parallel using [OpenMP](https://en.wikipedia.org/wiki/OpenMP)
. See the [parallel algorithms](https://graph-tool.skewed.de/static/docs/stable/parallel.html#parallel-algorithms)
section for information about how to control several aspects of parallelization.
References
\[[pagerank-wikipedia](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#id1)\
\]
[http://en.wikipedia.org/wiki/Pagerank](http://en.wikipedia.org/wiki/Pagerank)
\[lawrence-pagerank-1998\]
P. Lawrence, B. Sergey, M. Rajeev, W. Terry, “The pagerank citation ranking: Bringing order to the web”, Technical report, Stanford University, 1998
\[Langville-survey-2005\]
A. N. Langville, C. D. Meyer, “A Survey of Eigenvector Methods for Web Information Retrieval”, SIAM Review, vol. 47, no. 1, pp. 135-161, 2005, [DOI: 10.1137/S0036144503424786](https://dx.doi.org/10.1137/S0036144503424786)
\[[sci-hub](https://sci-hub.ru/10.1137/S0036144503424786)\
, [@tor](https://scihub22266oqcxt.onion/10.1137/S0036144503424786)\
\]
\[adamic-polblogs\] ([1](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#id6)
,[2](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#id7)
)
L. A. Adamic and N. Glance, “The political blogosphere and the 2004 US Election”, in Proceedings of the WWW-2005 Workshop on the Weblogging Ecosystem (2005). [DOI: 10.1145/1134271.1134277](https://dx.doi.org/10.1145/1134271.1134277)
\[[sci-hub](https://sci-hub.ru/10.1145/1134271.1134277)\
, [@tor](https://scihub22266oqcxt.onion/10.1145/1134271.1134277)\
\]
Examples
\>>> g \= gt.collection.data\["polblogs"\]
\>>> g \= gt.GraphView(g, vfilt\=gt.label\_largest\_component(g))
\>>> pr \= gt.pagerank(g)
\>>> gt.graph\_draw(g, pos\=g.vp\["pos"\], vertex\_fill\_color\=pr,
... vertex\_size\=gt.prop\_to\_size(pr, mi\=5, ma\=15),
... vorder\=pr, vcmap\=matplotlib.cm.gist\_heat,
... output\="polblogs\_pr.pdf")
<...>
[](https://graph-tool.skewed.de/static/docs/stable/_images/polblogs_pr.png)
PageRank values of the a political blogs network of [\[adamic-polblogs\]](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#rb8d783549222-adamic-polblogs)
.[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#id8 "Link to this image")
Now with a personalization vector, and edge weights:
\>>> d \= g.degree\_property\_map("total")
\>>> periphery \= d.a <= 2
\>>> p \= g.new\_vertex\_property("double")
\>>> p.a\[periphery\] \= 100
\>>> pr \= gt.pagerank(g, pers\=p)
\>>> gt.graph\_draw(g, pos\=g.vp\["pos"\], vertex\_fill\_color\=pr,
... vertex\_size\=gt.prop\_to\_size(pr, mi\=5, ma\=15),
... vorder\=pr, vcmap\=matplotlib.cm.gist\_heat,
... output\="polblogs\_pr\_pers.pdf")
<...>
[](https://graph-tool.skewed.de/static/docs/stable/_images/polblogs_pr_pers.png)
Personalized PageRank values of the a political blogs network of [\[adamic-polblogs\]](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#rb8d783549222-adamic-polblogs)
, where vertices with very low degree are given artificially high scores.[#](https://graph-tool.skewed.de/static/docs/stable/autosummary/graph_tool.centrality.pagerank.html#id9 "Link to this image")
Contents
---
# Unknown
.. automodule:: graph\_tool.dynamics
---
# Unknown
.. automodule:: graph\_tool.generation
---
# Unknown
.. automodule:: graph\_tool.flow
---
# Unknown
.. \_draw: .. automodule:: graph\_tool.draw
---
# Unknown
.. automodule:: graph\_tool.correlations
---
# Unknown
.. automodule:: graph\_tool.collection
---
# Unknown
.. automodule:: graph\_tool.clustering
---
# Unknown
.. automodule:: graph\_tool.spectral
---
# Unknown
(sec\_faq)=
# FAQ
## How do I retrieve a vertex by its property map value?
There are two ways to achieve this. The first is using the
{func}\`~graph\_tool.util.find\_vertex\` function that searches for all
vertices with a given property map value. However, this function has a
$O(N)$ complexity, where $N$ is the number of nodes. This
means that it can be inefficient if the search is performed frequently.
The second approach is to perform this lookup quickly, in $O(1)$
time, but it requires the user to keep her own dictionary that maps
vertices to property values, e.g.:
\`\`\`{doctest}
>>> from collections import defaultdict
>>> g = gt.Graph()
>>> g.gp.vmap = g.new\_gp("object", val=defaultdict(list))
>>> def add\_vertex(g, prop, value):
... v = g.add\_vertex()
... prop\[v\] = value
... g.gp.vmap\[value\].append(v)
... return g
>>> name = g.new\_vp("string")
>>> add\_vertex(g, name, "bob")
<...>
>>> add\_vertex(g, name, "eve")
<...>
>>> add\_vertex(g, name, "steve")
<...>
>>> g.gp.vmap\["eve"\]
\[\]
\`\`\`
:::{admonition} Why not include this functionality automatically?
Property map values are not guaranteed to be unique, therefore
there's no inherent bijection between property map values and their
corresponding vertices.
Note that, in the example above, the user still needs to manually
modify \`g.gp.vmap\` whenever a value of the property map \`name\`
has changed. To enforce this kind of bookkeeping throughout the
library would incur a prohibitive performance cost — not to mention
a significant increase in complexity.
:::
## Is it possible to perform modularity maximization with \`graph-tool\`?
It is in fact possible to perform modularity maximization with
\`graph-tool\`. For that you need to use the
{class}\`~graph\_tool.inference.ModularityState\` object instead
of {class}\`graph\_tool.inference.BlockState\`, as documented in
the section {ref}\`inference-howto\`, e.g.
\`\`\`{doctest}
>>> g = gt.collection.data\["football"\]
>>> state = gt.minimize\_blockmodel\_dl(g, state=gt.ModularityState)
\`\`\`
:::{danger}
Using modularity maximization is almost always \*\*a terrible idea\*\*.
Modularity maximization is a substantially inferior method to the
inference-based ones that are implemented in \`graph-tool\`, since it
does not possess any kind of statistical regularization. Among many
other problems, the method tends to massively overfit empirical data.
For a more detailed explanation see \[“Modularity maximization\
considered harmfulâ€\](https://skewed.de/lab/posts/modularity-harmful), as well as
\[^cite\_descriptive\].
Do not use this approach in the analysis of networks without
understanding the consequences. This algorithm is included only for
comparison purposes. In general, the inference-based approaches based
on {class}\`~graph\_tool.inference.BlockState\`,
{class}\`~graph\_tool.inference.NestedBlockState\`, and
{class}\`~graph\_tool.inference.PPBlockState\` should be universally
preferred.
:::
## How do I cite graph-tool?
You can cite graph-tool in your publications as follows:
> Tiago P. Peixoto, "The graph-tool python library", figshare. (2014)
> {doi}\`10.6084/m9.figshare.1164194\`
Here is a more convenient \[BibTeX\](http://www.bibtex.org) entry:
\`\`\`none
@article{peixoto\_graph-tool\_2014,
title = {The graph-tool python library},
url = {http://figshare.com/articles/graph\_tool/1164194},
doi = {10.6084/m9.figshare.1164194},
urldate = {2014-09-10},
journal = {figshare},
author = {Peixoto, Tiago P.},
year = {2014},
keywords = {all, complex networks, graph, network, other}}
\`\`\`
More information can be found at the \[figshare site\](http://figshare.com/articles/graph\_tool/1164194).
\[^cite\_descriptive\]: Tiago P. Peixoto, \*“Descriptive vs. inferential community
detection in networks: pitfalls, myths and half-truthsâ€\*, Elements in the
Structure and Dynamics of Complex Networks, Cambridge University Press
(2023), {doi}\`10.1017/9781009118897\` {arxiv}\`2112.00183\`
---
# Unknown
.. automodule:: graph\_tool.util
---
# Unknown
.. automodule:: graph\_tool.stats
---
# Unknown
.. automodule:: graph\_tool.topology
---
# Unknown
(sec\_gt\_format)=
# The \`gt\` file format
The \`gt\` file format is a simple binary format designed to store
graph-tool {class}\`~graph\_tool.Graph\` instances in a compact and fast
manner, including all types of property maps supported by the
library. It serves as an alternative to the text-based \[graphml\](http://graphml.graphdrawing.org/) format for very large graphs where
I/O may become very time and space consuming.
Here we describe the encoding in detail, using as an example the
\`lesmis\` network from the {mod}\`graph\_tool.collection\` module.
The header begins with the magic string \`⛾ gt\` in utf-8 encoding,
totaling 6 bytes, followed by the version number (currently \`0x01\`) in
a single byte, and a Boolean (also a single byte) determining the
\[endianness\](https://en.wikipedia.org/wiki/Endianness) (\`0x00\`:
little-endian, \`0x01\`: big-endian):
\`\`\`none
00000000 e2 9b be 20 67 74 01 00 |... gt..|
00000008
\`\`\`
This is followed by a comment string. Strings are stored by a length (8
bytes, \`uint64\_t\`) and the corresponding sequence of bytes, not
null-terminated. The comment may be empty, but graph-tool outputs a
human readable summary of the file, which can be inspected with tools
like \`hexdump\`:
\`\`\`none
00000000 e2 9b be 20 67 74 01 00 dd 00 00 00 00 00 00 00 |... gt..........|
00000010 67 72 61 70 68 2d 74 6f 6f 6c 20 62 69 6e 61 72 |graph-tool binar|
00000020 79 20 66 69 6c 65 20 28 68 74 74 70 3a 3a 2f 2f |y file (http:://|
00000030 67 72 61 70 68 2d 74 6f 6f 6c 2e 73 6b 65 77 65 |graph-tool.skewe|
00000040 64 2e 64 65 29 20 67 65 6e 65 72 61 74 65 64 20 |d.de) generated |
00000050 62 79 20 76 65 72 73 69 6f 6e 20 32 2e 32 2e 33 |by version 2.2.3|
00000060 32 64 65 76 20 28 63 6f 6d 6d 69 74 20 64 34 66 |2dev (commit d4f|
00000070 31 66 31 62 66 2c 20 4d 6f 6e 20 41 75 67 20 31 |1f1bf, Mon Aug 1|
00000080 31 20 31 36 3a 32 36 3a 35 34 20 32 30 31 34 20 |1 16:26:54 2014 |
00000090 2b 30 32 30 30 29 20 73 74 61 74 73 3a 20 37 37 |+0200) stats: 77|
000000a0 20 76 65 72 74 69 63 65 73 2c 20 32 35 34 20 65 | vertices, 254 e|
000000b0 64 67 65 73 2c 20 75 6e 64 69 72 65 63 74 65 64 |dges, undirected|
000000c0 2c 20 32 20 67 72 61 70 68 20 70 72 6f 70 73 2c |, 2 graph props,|
000000d0 20 32 20 76 65 72 74 65 78 20 70 72 6f 70 73 2c | 2 vertex props,|
000000e0 20 31 20 65 64 67 65 20 70 72 6f 70 73 | 1 edge props|
000000ed
\`\`\`
The adjacency list now follows, beginning with a Boolean byte specifying
whether or not the graph is directed (\`0x00\`: undirected, \`0x01\`:
directed), and 8 bytes (\`uint64\_t\`) containing the number of nodes,
\`N\`. It is followed by the list of out-neighbors of all \`N\` nodes
in sequence. The sequence itself determines implicitly the index of the
nodes, in the range from \`0\` to \`N-1\`. The list of out-neighbors of
a given node is composed of a length (8 bytes, \`uint64\_t\`) and a
sequence of node indices with this length. The number of bytes \`d\`
used to encode the node indices in this list is determined by the value
of \`N\`, and will be the smallest value of the set \`{1, 2, 4, 8}\`
(i.e. \`{uint8\_t, uint16\_t, uint32\_t, uint64\_t}\`, respectively) which
is sufficient to accommodate all \`N\` nodes. For undirected graphs,
here it is important that each edge appears only once, i.e. if node
\`u\` appears in the list of neighbors of \`v\`, then \`v\` \*\*should
not\*\* appear in the list of \`u\` again, otherwise it will be considered
as a different (parallel) edge. In this way, the total number of bytes
used for the adjacency is \`1 + 8 + N \* 8 + E \* d\` with \`E\` being the
number of edges:
\`\`\`none
00000000 e2 9b be 20 67 74 01 00 dd 00 00 00 00 00 00 00 |... gt..........|
00000010 67 72 61 70 68 2d 74 6f 6f 6c 20 62 69 6e 61 72 |graph-tool binar|
00000020 79 20 66 69 6c 65 20 28 68 74 74 70 3a 3a 2f 2f |y file (http:://|
00000030 67 72 61 70 68 2d 74 6f 6f 6c 2e 73 6b 65 77 65 |graph-tool.skewe|
00000040 64 2e 64 65 29 20 67 65 6e 65 72 61 74 65 64 20 |d.de) generated |
00000050 62 79 20 76 65 72 73 69 6f 6e 20 32 2e 32 2e 33 |by version 2.2.3|
00000060 32 64 65 76 20 28 63 6f 6d 6d 69 74 20 64 34 66 |2dev (commit d4f|
00000070 31 66 31 62 66 2c 20 4d 6f 6e 20 41 75 67 20 31 |1f1bf, Mon Aug 1|
00000080 31 20 31 36 3a 32 36 3a 35 34 20 32 30 31 34 20 |1 16:26:54 2014 |
00000090 2b 30 32 30 30 29 20 73 74 61 74 73 3a 20 37 37 |+0200) stats: 77|
000000a0 20 76 65 72 74 69 63 65 73 2c 20 32 35 34 20 65 | vertices, 254 e|
000000b0 64 67 65 73 2c 20 75 6e 64 69 72 65 63 74 65 64 |dges, undirected|
000000c0 2c 20 32 20 67 72 61 70 68 20 70 72 6f 70 73 2c |, 2 graph props,|
000000d0 20 32 20 76 65 72 74 65 78 20 70 72 6f 70 73 2c | 2 vertex props,|
000000e0 20 31 20 65 64 67 65 20 70 72 6f 70 73 00 4d 00 | 1 edge props.M.|
000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 |................|
00000100 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 |................|
00000110 02 00 00 00 00 00 00 00 00 02 01 00 00 00 00 00 |................|
00000120 00 00 00 01 00 00 00 00 00 00 00 00 01 00 00 00 |................|
00000130 00 00 00 00 00 01 00 00 00 00 00 00 00 00 01 00 |................|
00000140 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 |................|
00000150 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 |................|
00000160 0a 03 02 00 01 00 00 00 00 00 00 00 0b 01 00 00 |................|
00000170 00 00 00 00 00 0b 01 00 00 00 00 00 00 00 0b 01 |................|
00000180 00 00 00 00 00 00 00 0b 00 00 00 00 00 00 00 00 |................|
00000190 01 00 00 00 00 00 00 00 10 02 00 00 00 00 00 00 |................|
000001a0 00 10 11 03 00 00 00 00 00 00 00 10 11 12 04 00 |................|
000001b0 00 00 00 00 00 00 10 11 12 13 05 00 00 00 00 00 |................|
000001c0 00 00 10 11 12 13 14 06 00 00 00 00 00 00 00 10 |................|
000001d0 11 12 13 14 15 09 00 00 00 00 00 00 00 10 11 12 |................|
000001e0 13 14 15 16 0c 0b 02 00 00 00 00 00 00 00 17 0b |................|
000001f0 03 00 00 00 00 00 00 00 18 17 0b 04 00 00 00 00 |................|
00000200 00 00 00 18 0b 10 19 05 00 00 00 00 00 00 00 0b |................|
00000210 17 19 18 1a 02 00 00 00 00 00 00 00 0b 1b 03 00 |................|
00000220 00 00 00 00 00 00 17 1b 0b 01 00 00 00 00 00 00 |................|
00000230 00 17 04 00 00 00 00 00 00 00 1e 0b 17 1b 01 00 |................|
00000240 00 00 00 00 00 00 0b 02 00 00 00 00 00 00 00 0b |................|
00000250 1b 02 00 00 00 00 00 00 00 0b 1d 03 00 00 00 00 |................|
00000260 00 00 00 0b 22 1d 04 00 00 00 00 00 00 00 22 23 |...."........."#|
00000270 0b 1d 05 00 00 00 00 00 00 00 22 23 24 0b 1d 06 |.........."#$...|
00000280 00 00 00 00 00 00 00 22 23 24 25 0b 1d 01 00 00 |......."#$%.....|
00000290 00 00 00 00 00 19 01 00 00 00 00 00 00 00 19 02 |................|
000002a0 00 00 00 00 00 00 00 18 19 03 00 00 00 00 00 00 |................|
000002b0 00 29 19 18 03 00 00 00 00 00 00 00 0b 1a 1b 02 |.)..............|
000002c0 00 00 00 00 00 00 00 1c 0b 01 00 00 00 00 00 00 |................|
000002d0 00 1c 00 00 00 00 00 00 00 00 01 00 00 00 00 00 |................|
000002e0 00 00 2e 04 00 00 00 00 00 00 00 2f 19 1b 0b 02 |.........../....|
000002f0 00 00 00 00 00 00 00 1a 0b 02 00 00 00 00 00 00 |................|
00000300 00 31 18 03 00 00 00 00 00 00 00 31 1a 0b 02 00 |.1.........1....|
00000310 00 00 00 00 00 00 33 27 01 00 00 00 00 00 00 00 |......3'........|
00000320 33 03 00 00 00 00 00 00 00 33 31 1a 0a 00 00 00 |3........31.....|
00000330 00 00 00 00 33 31 27 36 1a 0b 10 19 29 30 02 00 |....31'6....)0..|
00000340 00 00 00 00 00 00 31 37 03 00 00 00 00 00 00 00 |......17........|
00000350 37 29 30 05 00 00 00 00 00 00 00 37 30 1b 39 0b |7)0........70.9.|
00000360 04 00 00 00 00 00 00 00 3a 37 30 39 03 00 00 00 |........:709....|
00000370 00 00 00 00 30 3a 3b 06 00 00 00 00 00 00 00 30 |....0:;........0|
00000380 3a 3c 3b 39 37 08 00 00 00 00 00 00 00 37 3a 3b |:<;97........7:;|
00000390 30 39 29 3d 3c 08 00 00 00 00 00 00 00 3b 30 3e |09)=<........;0>|
000003a0 39 3a 3d 3c 37 0a 00 00 00 00 00 00 00 37 3e 30 |9:=<7........7>0|
000003b0 3f 3a 3d 3c 3b 39 0b 0a 00 00 00 00 00 00 00 3f |?:=<;9.........?|
000003c0 40 30 3e 3a 3d 3c 3b 39 37 09 00 00 00 00 00 00 |@0>:=<;97.......|
000003d0 00 40 3a 3b 3e 41 30 3f 3d 3c 01 00 00 00 00 00 |.@:;>A0?=<......|
000003e0 00 00 39 06 00 00 00 00 00 00 00 19 0b 18 1b 30 |..9............0|
000003f0 29 07 00 00 00 00 00 00 00 19 44 0b 18 1b 30 29 |).........D...0)|
00000400 08 00 00 00 00 00 00 00 19 45 44 0b 18 1b 29 3a |.........ED...):|
00000410 08 00 00 00 00 00 00 00 1b 45 44 46 0b 30 29 19 |.........EDF.0).|
00000420 03 00 00 00 00 00 00 00 1a 1b 0b 01 00 00 00 00 |................|
00000430 00 00 00 30 02 00 00 00 00 00 00 00 30 49 07 00 |...0........0I..|
00000440 00 00 00 00 00 00 45 44 19 30 29 46 47 07 00 00 |......ED.0)FG...|
00000450 00 00 00 00 00 40 41 42 3f 3e 30 3a |.....@AB?>0:|
0000045c
\`\`\`
The adjacency is followed by a list of property maps. The list begins
with a total number of property maps (8 bytes, \`uint64\_t\`), and then
the individual records. Each property map begins with a key type (1
byte, \`uint8\_t\`) specifying whether it is a graph (\`0x00\`), a vertex
(\`0x01\`) or an edge (\`0x02\`) property map, followed by a string (8
byte length + length bytes) containing the name of the property
map. This is then followed by a byte (\`uint8\_t\`) specifying the value
type index, from the following table:
\`\`\`{eval-rst}
.. tabularcolumns:: |l|l|
\`\`\`
\`\`\`{eval-rst}
.. table::
======================== =================== ========
Type name Bytes Index
======================== =================== ========
\`\`bool\`\` \`\`1\`\` \`\`0x00\`\`
\`\`int16\_t\`\` \`\`2\`\` \`\`0x01\`\`
\`\`int32\_t\`\` \`\`4\`\` \`\`0x02\`\`
\`\`int64\_t\`\` \`\`8\`\` \`\`0x03\`\`
\`\`double\`\` \`\`8\`\` \`\`0x04\`\`
\`\`long double\`\` \`\`16\`\` \`\`0x05\`\`
\`\`string\`\` \`\`8 + length\`\` \`\`0x06\`\`
\`\`vector\`\` \`\`8 + length\`\` \`\`0x07\`\`
\`\`vector\`\` \`\`8 + 2 \* length\`\` \`\`0x08\`\`
\`\`vector\`\` \`\`8 + 4 \* length\`\` \`\`0x09\`\`
\`\`vector\`\` \`\`8 + 8 \* length\`\` \`\`0x0a\`\`
\`\`vector\`\` \`\`8 + 8 \* length\`\` \`\`0x0b\`\`
\`\`vector\`\` \`\`8 + 16 \* length\`\` \`\`0x0c\`\`
\`\`vector\`\` \`\`8 + \`\` \`\`0x0d\`\`
\`\`python::object\`\` \`\`8 + length\`\` \`\`0x0e\`\`
======================== =================== ========
\`\`\`
The values of the property map follow in the order of the vertex indices
(for vertex properties) or in the same order in which the edges appear
in the preceding adjacency list (for edge properties). For graph
properties only one value follows. Strings and vectors are encoded with
a length prefix of 8 bytes (\`uint64\_t\`) followed by a sequence of that
size with the appropriate element size. The elements of
\`vector\` are encoded as pairs of (8 byte length, bytes) as
usual. Values of type \`python::object\` are encoded just as strings,
with the string content encoded or decoded via {mod}\`pickle\`.
\`\`\`none
00000000 e2 9b be 20 67 74 01 00 dd 00 00 00 00 00 00 00 |... gt..........|
00000010 67 72 61 70 68 2d 74 6f 6f 6c 20 62 69 6e 61 72 |graph-tool binar|
00000020 79 20 66 69 6c 65 20 28 68 74 74 70 3a 3a 2f 2f |y file (http:://|
00000030 67 72 61 70 68 2d 74 6f 6f 6c 2e 73 6b 65 77 65 |graph-tool.skewe|
00000040 64 2e 64 65 29 20 67 65 6e 65 72 61 74 65 64 20 |d.de) generated |
00000050 62 79 20 76 65 72 73 69 6f 6e 20 32 2e 32 2e 33 |by version 2.2.3|
00000060 32 64 65 76 20 28 63 6f 6d 6d 69 74 20 64 34 66 |2dev (commit d4f|
00000070 31 66 31 62 66 2c 20 4d 6f 6e 20 41 75 67 20 31 |1f1bf, Mon Aug 1|
00000080 31 20 31 36 3a 32 36 3a 35 34 20 32 30 31 34 20 |1 16:26:54 2014 |
00000090 2b 30 32 30 30 29 20 73 74 61 74 73 3a 20 37 37 |+0200) stats: 77|
000000a0 20 76 65 72 74 69 63 65 73 2c 20 32 35 34 20 65 | vertices, 254 e|
000000b0 64 67 65 73 2c 20 75 6e 64 69 72 65 63 74 65 64 |dges, undirected|
000000c0 2c 20 32 20 67 72 61 70 68 20 70 72 6f 70 73 2c |, 2 graph props,|
000000d0 20 32 20 76 65 72 74 65 78 20 70 72 6f 70 73 2c | 2 vertex props,|
000000e0 20 31 20 65 64 67 65 20 70 72 6f 70 73 00 4d 00 | 1 edge props.M.|
000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 |................|
00000100 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 |................|
00000110 02 00 00 00 00 00 00 00 00 02 01 00 00 00 00 00 |................|
00000120 00 00 00 01 00 00 00 00 00 00 00 00 01 00 00 00 |................|
00000130 00 00 00 00 00 01 00 00 00 00 00 00 00 00 01 00 |................|
00000140 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 |................|
00000150 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 |................|
00000160 0a 03 02 00 01 00 00 00 00 00 00 00 0b 01 00 00 |................|
00000170 00 00 00 00 00 0b 01 00 00 00 00 00 00 00 0b 01 |................|
00000180 00 00 00 00 00 00 00 0b 00 00 00 00 00 00 00 00 |................|
00000190 01 00 00 00 00 00 00 00 10 02 00 00 00 00 00 00 |................|
000001a0 00 10 11 03 00 00 00 00 00 00 00 10 11 12 04 00 |................|
000001b0 00 00 00 00 00 00 10 11 12 13 05 00 00 00 00 00 |................|
000001c0 00 00 10 11 12 13 14 06 00 00 00 00 00 00 00 10 |................|
000001d0 11 12 13 14 15 09 00 00 00 00 00 00 00 10 11 12 |................|
000001e0 13 14 15 16 0c 0b 02 00 00 00 00 00 00 00 17 0b |................|
000001f0 03 00 00 00 00 00 00 00 18 17 0b 04 00 00 00 00 |................|
00000200 00 00 00 18 0b 10 19 05 00 00 00 00 00 00 00 0b |................|
00000210 17 19 18 1a 02 00 00 00 00 00 00 00 0b 1b 03 00 |................|
00000220 00 00 00 00 00 00 17 1b 0b 01 00 00 00 00 00 00 |................|
00000230 00 17 04 00 00 00 00 00 00 00 1e 0b 17 1b 01 00 |................|
00000240 00 00 00 00 00 00 0b 02 00 00 00 00 00 00 00 0b |................|
00000250 1b 02 00 00 00 00 00 00 00 0b 1d 03 00 00 00 00 |................|
00000260 00 00 00 0b 22 1d 04 00 00 00 00 00 00 00 22 23 |...."........."#|
00000270 0b 1d 05 00 00 00 00 00 00 00 22 23 24 0b 1d 06 |.........."#$...|
00000280 00 00 00 00 00 00 00 22 23 24 25 0b 1d 01 00 00 |......."#$%.....|
00000290 00 00 00 00 00 19 01 00 00 00 00 00 00 00 19 02 |................|
000002a0 00 00 00 00 00 00 00 18 19 03 00 00 00 00 00 00 |................|
000002b0 00 29 19 18 03 00 00 00 00 00 00 00 0b 1a 1b 02 |.)..............|
000002c0 00 00 00 00 00 00 00 1c 0b 01 00 00 00 00 00 00 |................|
000002d0 00 1c 00 00 00 00 00 00 00 00 01 00 00 00 00 00 |................|
000002e0 00 00 2e 04 00 00 00 00 00 00 00 2f 19 1b 0b 02 |.........../....|
000002f0 00 00 00 00 00 00 00 1a 0b 02 00 00 00 00 00 00 |................|
00000300 00 31 18 03 00 00 00 00 00 00 00 31 1a 0b 02 00 |.1.........1....|
00000310 00 00 00 00 00 00 33 27 01 00 00 00 00 00 00 00 |......3'........|
00000320 33 03 00 00 00 00 00 00 00 33 31 1a 0a 00 00 00 |3........31.....|
00000330 00 00 00 00 33 31 27 36 1a 0b 10 19 29 30 02 00 |....31'6....)0..|
00000340 00 00 00 00 00 00 31 37 03 00 00 00 00 00 00 00 |......17........|
00000350 37 29 30 05 00 00 00 00 00 00 00 37 30 1b 39 0b |7)0........70.9.|
00000360 04 00 00 00 00 00 00 00 3a 37 30 39 03 00 00 00 |........:709....|
00000370 00 00 00 00 30 3a 3b 06 00 00 00 00 00 00 00 30 |....0:;........0|
00000380 3a 3c 3b 39 37 08 00 00 00 00 00 00 00 37 3a 3b |:<;97........7:;|
00000390 30 39 29 3d 3c 08 00 00 00 00 00 00 00 3b 30 3e |09)=<........;0>|
000003a0 39 3a 3d 3c 37 0a 00 00 00 00 00 00 00 37 3e 30 |9:=<7........7>0|
000003b0 3f 3a 3d 3c 3b 39 0b 0a 00 00 00 00 00 00 00 3f |?:=<;9.........?|
000003c0 40 30 3e 3a 3d 3c 3b 39 37 09 00 00 00 00 00 00 |@0>:=<;97.......|
000003d0 00 40 3a 3b 3e 41 30 3f 3d 3c 01 00 00 00 00 00 |.@:;>A0?=<......|
000003e0 00 00 39 06 00 00 00 00 00 00 00 19 0b 18 1b 30 |..9............0|
000003f0 29 07 00 00 00 00 00 00 00 19 44 0b 18 1b 30 29 |).........D...0)|
00000400 08 00 00 00 00 00 00 00 19 45 44 0b 18 1b 29 3a |.........ED...):|
00000410 08 00 00 00 00 00 00 00 1b 45 44 46 0b 30 29 19 |.........EDF.0).|
00000420 03 00 00 00 00 00 00 00 1a 1b 0b 01 00 00 00 00 |................|
00000430 00 00 00 30 02 00 00 00 00 00 00 00 30 49 07 00 |...0........0I..|
00000440 00 00 00 00 00 00 45 44 19 30 29 46 47 07 00 00 |......ED.0)FG...|
00000450 00 00 00 00 00 40 41 42 3f 3e 30 3a 05 00 00 00 |.....@AB?>0:....|
00000460 00 00 00 00 00 0b 00 00 00 00 00 00 00 64 65 73 |.............des|
00000470 63 72 69 70 74 69 6f 6e 06 24 01 00 00 00 00 00 |cription.$......|
00000480 00 4c 65 73 20 4d 69 73 65 72 61 62 6c 65 73 3a |.Les Miserables:|
00000490 20 63 6f 61 70 70 65 61 72 61 6e 63 65 20 6e 65 | coappearance ne|
000004a0 74 77 6f 72 6b 20 6f 66 20 63 68 61 72 61 63 74 |twork of charact|
000004b0 65 72 73 20 69 6e 20 74 68 65 20 6e 6f 76 65 6c |ers in the novel|
000004c0 20 4c 65 73 20 4d 69 73 65 72 61 62 6c 65 73 2e | Les Miserables.|
000004d0 20 50 6c 65 61 73 65 20 63 69 74 65 20 44 2e 20 | Please cite D. |
000004e0 45 2e 20 4b 6e 75 74 68 2c 20 54 68 65 20 53 74 |E. Knuth, The St|
000004f0 61 6e 66 6f 72 64 20 47 72 61 70 68 42 61 73 65 |anford GraphBase|
00000500 3a 20 41 20 50 6c 61 74 66 6f 72 6d 20 66 6f 72 |: A Platform for|
00000510 20 43 6f 6d 62 69 6e 61 74 6f 72 69 61 6c 20 43 | Combinatorial C|
00000520 6f 6d 70 75 74 69 6e 67 2c 20 41 64 64 69 73 6f |omputing, Addiso|
00000530 6e 2d 57 65 73 6c 65 79 2c 20 52 65 61 64 69 6e |n-Wesley, Readin|
00000540 67 2c 20 4d 41 20 28 31 39 39 33 29 2e 20 52 65 |g, MA (1993). Re|
00000550 74 72 69 65 76 65 64 20 66 72 6f 6d 20 60 4d 61 |trieved from \`Ma|
00000560 72 6b 20 4e 65 77 6d 61 6e 27 73 20 77 65 62 73 |rk Newman's webs|
00000570 69 74 65 20 3c 68 74 74 70 3a 2f 2f 77 77 77 2d |ite \`\_..........re|
000005b0 61 64 6d 65 06 e2 01 00 00 00 00 00 00 54 68 65 |adme.........The|
000005c0 20 66 69 6c 65 20 6c 65 73 6d 69 73 2e 67 6d 6c | file lesmis.gml|
000005d0 20 63 6f 6e 74 61 69 6e 73 20 74 68 65 20 77 65 | contains the we|
000005e0 69 67 68 74 65 64 20 6e 65 74 77 6f 72 6b 20 6f |ighted network o|
000005f0 66 20 63 6f 61 70 70 65 61 72 61 6e 63 65 73 20 |f coappearances |
00000600 6f 66 0a 63 68 61 72 61 63 74 65 72 73 20 69 6e |of.characters in|
00000610 20 56 69 63 74 6f 72 20 48 75 67 6f 27 73 20 6e | Victor Hugo's n|
00000620 6f 76 65 6c 20 22 4c 65 73 20 4d 69 73 65 72 61 |ovel "Les Misera|
00000630 62 6c 65 73 22 2e 20 20 4e 6f 64 65 73 20 72 65 |bles". Nodes re|
00000640 70 72 65 73 65 6e 74 0a 63 68 61 72 61 63 74 65 |present.characte|
00000650 72 73 20 61 73 20 69 6e 64 69 63 61 74 65 64 20 |rs as indicated |
00000660 62 79 20 74 68 65 20 6c 61 62 65 6c 73 20 61 6e |by the labels an|
00000670 64 20 65 64 67 65 73 20 63 6f 6e 6e 65 63 74 20 |d edges connect |
00000680 61 6e 79 20 70 61 69 72 20 6f 66 0a 63 68 61 72 |any pair of.char|
00000690 61 63 74 65 72 73 20 74 68 61 74 20 61 70 70 65 |acters that appe|
000006a0 61 72 20 69 6e 20 74 68 65 20 73 61 6d 65 20 63 |ar in the same c|
000006b0 68 61 70 74 65 72 20 6f 66 20 74 68 65 20 62 6f |hapter of the bo|
000006c0 6f 6b 2e 20 20 54 68 65 20 76 61 6c 75 65 73 20 |ok. The values |
000006d0 6f 6e 20 74 68 65 0a 65 64 67 65 73 20 61 72 65 |on the.edges are|
000006e0 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 73 | the number of s|
000006f0 75 63 68 20 63 6f 61 70 70 65 61 72 61 6e 63 65 |uch coappearance|
00000700 73 2e 20 20 54 68 65 20 64 61 74 61 20 6f 6e 20 |s. The data on |
00000710 63 6f 61 70 70 65 61 72 61 6e 63 65 73 20 77 65 |coappearances we|
00000720 72 65 0a 74 61 6b 65 6e 20 66 72 6f 6d 20 44 2e |re.taken from D.|
00000730 20 45 2e 20 4b 6e 75 74 68 2c 20 54 68 65 20 53 | E. Knuth, The S|
00000740 74 61 6e 66 6f 72 64 20 47 72 61 70 68 42 61 73 |tanford GraphBas|
00000750 65 3a 20 41 20 50 6c 61 74 66 6f 72 6d 20 66 6f |e: A Platform fo|
00000760 72 0a 43 6f 6d 62 69 6e 61 74 6f 72 69 61 6c 20 |r.Combinatorial |
00000770 43 6f 6d 70 75 74 69 6e 67 2c 20 41 64 64 69 73 |Computing, Addis|
00000780 6f 6e 2d 57 65 73 6c 65 79 2c 20 52 65 61 64 69 |on-Wesley, Readi|
00000790 6e 67 2c 20 4d 41 20 28 31 39 39 33 29 2e 0a 01 |ng, MA (1993)...|
000007a0 05 00 00 00 00 00 00 00 6c 61 62 65 6c 06 06 00 |........label...|
000007b0 00 00 00 00 00 00 4d 79 72 69 65 6c 08 00 00 00 |......Myriel....|
000007c0 00 00 00 00 4e 61 70 6f 6c 65 6f 6e 0e 00 00 00 |....Napoleon....|
000007d0 00 00 00 00 4d 6c 6c 65 42 61 70 74 69 73 74 69 |....MlleBaptisti|
000007e0 6e 65 0b 00 00 00 00 00 00 00 4d 6d 65 4d 61 67 |ne........MmeMag|
000007f0 6c 6f 69 72 65 0c 00 00 00 00 00 00 00 43 6f 75 |loire........Cou|
00000800 6e 74 65 73 73 44 65 4c 6f 08 00 00 00 00 00 00 |ntessDeLo.......|
00000810 00 47 65 62 6f 72 61 6e 64 0c 00 00 00 00 00 00 |.Geborand.......|
00000820 00 43 68 61 6d 70 74 65 72 63 69 65 72 08 00 00 |.Champtercier...|
00000830 00 00 00 00 00 43 72 61 76 61 74 74 65 05 00 00 |.....Cravatte...|
00000840 00 00 00 00 00 43 6f 75 6e 74 06 00 00 00 00 00 |.....Count......|
00000850 00 00 4f 6c 64 4d 61 6e 07 00 00 00 00 00 00 00 |..OldMan........|
00000860 4c 61 62 61 72 72 65 07 00 00 00 00 00 00 00 56 |Labarre........V|
00000870 61 6c 6a 65 61 6e 0a 00 00 00 00 00 00 00 4d 61 |aljean........Ma|
00000880 72 67 75 65 72 69 74 65 06 00 00 00 00 00 00 00 |rguerite........|
00000890 4d 6d 65 44 65 52 07 00 00 00 00 00 00 00 49 73 |MmeDeR........Is|
000008a0 61 62 65 61 75 07 00 00 00 00 00 00 00 47 65 72 |abeau........Ger|
000008b0 76 61 69 73 09 00 00 00 00 00 00 00 54 68 6f 6c |vais........Thol|
000008c0 6f 6d 79 65 73 09 00 00 00 00 00 00 00 4c 69 73 |omyes........Lis|
000008d0 74 6f 6c 69 65 72 07 00 00 00 00 00 00 00 46 61 |tolier........Fa|
000008e0 6d 65 75 69 6c 0b 00 00 00 00 00 00 00 42 6c 61 |meuil........Bla|
000008f0 63 68 65 76 69 6c 6c 65 09 00 00 00 00 00 00 00 |cheville........|
00000900 46 61 76 6f 75 72 69 74 65 06 00 00 00 00 00 00 |Favourite.......|
00000910 00 44 61 68 6c 69 61 07 00 00 00 00 00 00 00 5a |.Dahlia........Z|
00000920 65 70 68 69 6e 65 07 00 00 00 00 00 00 00 46 61 |ephine........Fa|
00000930 6e 74 69 6e 65 0d 00 00 00 00 00 00 00 4d 6d 65 |ntine........Mme|
00000940 54 68 65 6e 61 72 64 69 65 72 0a 00 00 00 00 00 |Thenardier......|
00000950 00 00 54 68 65 6e 61 72 64 69 65 72 07 00 00 00 |..Thenardier....|
00000960 00 00 00 00 43 6f 73 65 74 74 65 06 00 00 00 00 |....Cosette.....|
00000970 00 00 00 4a 61 76 65 72 74 0c 00 00 00 00 00 00 |...Javert.......|
00000980 00 46 61 75 63 68 65 6c 65 76 65 6e 74 0a 00 00 |.Fauchelevent...|
00000990 00 00 00 00 00 42 61 6d 61 74 61 62 6f 69 73 08 |.....Bamatabois.|
000009a0 00 00 00 00 00 00 00 50 65 72 70 65 74 75 65 08 |.......Perpetue.|
000009b0 00 00 00 00 00 00 00 53 69 6d 70 6c 69 63 65 0b |.......Simplice.|
000009c0 00 00 00 00 00 00 00 53 63 61 75 66 66 6c 61 69 |.......Scaufflai|
000009d0 72 65 06 00 00 00 00 00 00 00 57 6f 6d 61 6e 31 |re........Woman1|
000009e0 05 00 00 00 00 00 00 00 4a 75 64 67 65 0c 00 00 |........Judge...|
000009f0 00 00 00 00 00 43 68 61 6d 70 6d 61 74 68 69 65 |.....Champmathie|
00000a00 75 06 00 00 00 00 00 00 00 42 72 65 76 65 74 0a |u........Brevet.|
00000a10 00 00 00 00 00 00 00 43 68 65 6e 69 6c 64 69 65 |.......Chenildie|
00000a20 75 0b 00 00 00 00 00 00 00 43 6f 63 68 65 70 61 |u........Cochepa|
00000a30 69 6c 6c 65 09 00 00 00 00 00 00 00 50 6f 6e 74 |ille........Pont|
00000a40 6d 65 72 63 79 0c 00 00 00 00 00 00 00 42 6f 75 |mercy........Bou|
00000a50 6c 61 74 72 75 65 6c 6c 65 07 00 00 00 00 00 00 |latruelle.......|
00000a60 00 45 70 6f 6e 69 6e 65 07 00 00 00 00 00 00 00 |.Eponine........|
00000a70 41 6e 7a 65 6c 6d 61 06 00 00 00 00 00 00 00 57 |Anzelma........W|
00000a80 6f 6d 61 6e 32 0e 00 00 00 00 00 00 00 4d 6f 74 |oman2........Mot|
00000a90 68 65 72 49 6e 6e 6f 63 65 6e 74 07 00 00 00 00 |herInnocent.....|
00000aa0 00 00 00 47 72 69 62 69 65 72 09 00 00 00 00 00 |...Gribier......|
00000ab0 00 00 4a 6f 6e 64 72 65 74 74 65 09 00 00 00 00 |..Jondrette.....|
00000ac0 00 00 00 4d 6d 65 42 75 72 67 6f 6e 08 00 00 00 |...MmeBurgon....|
00000ad0 00 00 00 00 47 61 76 72 6f 63 68 65 0c 00 00 00 |....Gavroche....|
00000ae0 00 00 00 00 47 69 6c 6c 65 6e 6f 72 6d 61 6e 64 |....Gillenormand|
00000af0 06 00 00 00 00 00 00 00 4d 61 67 6e 6f 6e 10 00 |........Magnon..|
00000b00 00 00 00 00 00 00 4d 6c 6c 65 47 69 6c 6c 65 6e |......MlleGillen|
00000b10 6f 72 6d 61 6e 64 0c 00 00 00 00 00 00 00 4d 6d |ormand........Mm|
00000b20 65 50 6f 6e 74 6d 65 72 63 79 0b 00 00 00 00 00 |ePontmercy......|
00000b30 00 00 4d 6c 6c 65 56 61 75 62 6f 69 73 0e 00 00 |..MlleVaubois...|
00000b40 00 00 00 00 00 4c 74 47 69 6c 6c 65 6e 6f 72 6d |.....LtGillenorm|
00000b50 61 6e 64 06 00 00 00 00 00 00 00 4d 61 72 69 75 |and........Mariu|
00000b60 73 09 00 00 00 00 00 00 00 42 61 72 6f 6e 65 73 |s........Barones|
00000b70 73 54 06 00 00 00 00 00 00 00 4d 61 62 65 75 66 |sT........Mabeuf|
00000b80 08 00 00 00 00 00 00 00 45 6e 6a 6f 6c 72 61 73 |........Enjolras|
00000b90 0a 00 00 00 00 00 00 00 43 6f 6d 62 65 66 65 72 |........Combefer|
00000ba0 72 65 09 00 00 00 00 00 00 00 50 72 6f 75 76 61 |re........Prouva|
00000bb0 69 72 65 07 00 00 00 00 00 00 00 46 65 75 69 6c |ire........Feuil|
00000bc0 6c 79 0a 00 00 00 00 00 00 00 43 6f 75 72 66 65 |ly........Courfe|
00000bd0 79 72 61 63 07 00 00 00 00 00 00 00 42 61 68 6f |yrac........Baho|
00000be0 72 65 6c 07 00 00 00 00 00 00 00 42 6f 73 73 75 |rel........Bossu|
00000bf0 65 74 04 00 00 00 00 00 00 00 4a 6f 6c 79 09 00 |et........Joly..|
00000c00 00 00 00 00 00 00 47 72 61 6e 74 61 69 72 65 0e |......Grantaire.|
00000c10 00 00 00 00 00 00 00 4d 6f 74 68 65 72 50 6c 75 |.......MotherPlu|
00000c20 74 61 72 63 68 09 00 00 00 00 00 00 00 47 75 65 |tarch........Gue|
00000c30 75 6c 65 6d 65 72 05 00 00 00 00 00 00 00 42 61 |ulemer........Ba|
00000c40 62 65 74 0a 00 00 00 00 00 00 00 43 6c 61 71 75 |bet........Claqu|
00000c50 65 73 6f 75 73 0c 00 00 00 00 00 00 00 4d 6f 6e |esous........Mon|
00000c60 74 70 61 72 6e 61 73 73 65 09 00 00 00 00 00 00 |tparnasse.......|
00000c70 00 54 6f 75 73 73 61 69 6e 74 06 00 00 00 00 00 |.Toussaint......|
00000c80 00 00 43 68 69 6c 64 31 06 00 00 00 00 00 00 00 |..Child1........|
00000c90 43 68 69 6c 64 32 06 00 00 00 00 00 00 00 42 72 |Child2........Br|
00000ca0 75 6a 6f 6e 0c 00 00 00 00 00 00 00 4d 6d 65 48 |ujon........MmeH|
00000cb0 75 63 68 65 6c 6f 75 70 01 03 00 00 00 00 00 00 |ucheloup........|
00000cc0 00 70 6f 73 0b 02 00 00 00 00 00 00 00 6e c8 82 |.pos.........n..|
00000cd0 10 aa 06 a1 c0 92 2c ff 95 d9 9d 6c c0 02 00 00 |......,....l....|
00000ce0 00 00 00 00 00 63 e4 06 e4 7b fc a0 c0 1b 96 8c |.....c...{......|
00000cf0 84 16 45 6c c0 02 00 00 00 00 00 00 00 01 9e b0 |..El............|
00000d00 80 fe 0e a1 c0 53 f1 82 9b 28 a0 6c c0 02 00 00 |.....S...(.l....|
00000d10 00 00 00 00 00 2a 22 05 0b db 0d a1 c0 42 fb 82 |.....\*"......B..|
00000d20 44 e2 58 6c c0 02 00 00 00 00 00 00 00 85 c9 58 |D.Xl...........X|
00000d30 e8 95 fb a0 c0 be eb ce 9b 1c fa 6c c0 02 00 00 |...........l....|
00000d40 00 00 00 00 00 73 4d d1 51 dc ff a0 c0 bb 17 30 |.....sM.Q......0|
00000d50 1e 9e 37 6d c0 02 00 00 00 00 00 00 00 19 a9 01 |..7m............|
00000d60 fb 3e fa a0 c0 1e 6f 5c 53 7e 99 6c c0 02 00 00 |.>....o\\S~.l....|
00000d70 00 00 00 00 00 85 76 a4 9b 68 05 a1 c0 4e f1 63 |......v..h...N.c|
00000d80 ed 00 39 6d c0 02 00 00 00 00 00 00 00 0e 3b 97 |..9m..........;.|
00000d90 bb 07 00 a1 c0 1c 4e 73 a5 01 b9 6c c0 02 00 00 |......Ns...l....|
00000da0 00 00 00 00 00 e2 76 a4 90 6c 01 a1 c0 02 f4 76 |......v..l.....v|
00000db0 f6 8c 1b 6c c0 02 00 00 00 00 00 00 00 18 d7 fe |...l............|
00000dc0 98 da 0f a1 c0 74 e0 45 c8 15 df 6b c0 02 00 00 |.....t.E...k....|
00000dd0 00 00 00 00 00 4b d8 fb ec a9 1d a1 c0 b2 1c b8 |.....K..........|
00000de0 1a 4d 47 6c c0 02 00 00 00 00 00 00 00 05 b6 eb |.MGl............|
00000df0 85 23 25 a1 c0 35 18 91 b5 40 11 6d c0 02 00 00 |.#%..5...@.m....|
00000e00 00 00 00 00 00 6f 83 35 3d 7e 15 a1 c0 07 56 03 |.....o.5=~....V.|
00000e10 7c 6e e6 6b c0 02 00 00 00 00 00 00 00 45 d8 ae ||n.k.........E..|
00000e20 23 55 12 a1 c0 34 6e b5 11 41 2a 6c c0 02 00 00 |#U...4n..A\*l....|
00000e30 00 00 00 00 00 6a 3b 47 7b 1c 14 a1 c0 26 23 12 |.....j;G{.....|
00000e40 7b e3 99 6b c0 02 00 00 00 00 00 00 00 83 62 cf |{..k..........b.|
00000e50 40 3c 31 a1 c0 2f 1b 86 7f 10 a3 6c c0 02 00 00 |@<1../.....l....|
00000e60 00 00 00 00 00 cd f8 37 78 66 35 a1 c0 ed 4e 5b |.......7xf5...N\[|\
00000e70 77 b8 3a 6d c0 02 00 00 00 00 00 00 00 c2 d4 1d |w.:m............|\
00000e80 7b 23 36 a1 c0 90 0a be da 30 d4 6c c0 02 00 00 |{#6......0.l....|\
00000e90 00 00 00 00 00 e5 19 cc 64 8f 37 a1 c0 24 ad 21 |........d.7..$.!|\
00000ea0 9e bf 0b 6d c0 02 00 00 00 00 00 00 00 db b2 d0 |...m............|\
00000eb0 f8 2e 30 a1 c0 ad ae f8 8e 3e 13 6d c0 02 00 00 |..0......>.m....|\
00000ec0 00 00 00 00 00 73 a6 1c b1 e3 31 a1 c0 92 5b 84 |.....s....1...\[.|\
00000ed0 d8 81 47 6d c0 02 00 00 00 00 00 00 00 09 78 b8 |..Gm..........x.|\
00000ee0 9f 5a 33 a1 c0 de e8 fd a1 46 fa 6c c0 02 00 00 |.Z3......F.l....|\
00000ef0 00 00 00 00 00 01 60 9f ee 86 2b a1 c0 63 bc d3 |......\`...+..c..|\
00000f00 3a eb be 6c c0 02 00 00 00 00 00 00 00 76 28 90 |:..l.........v(.|\
00000f10 6c 93 27 a1 c0 42 b4 67 40 57 16 6c c0 02 00 00 |l.'..B.g@W.l....|\
00000f20 00 00 00 00 00 e7 c4 c6 49 45 27 a1 c0 41 ec 50 |........IE'..A.P|\
00000f30 f7 9f d3 6b c0 02 00 00 00 00 00 00 00 c4 10 23 |...k...........#|\
00000f40 90 3e 2a a1 c0 c4 1e 7b f8 30 3d 6c c0 02 00 00 |.>\*....{.0=l....|\
00000f50 00 00 00 00 00 01 0b d5 bc 11 22 a1 c0 4d e3 54 |.........."..M.T|\
00000f60 77 94 2d 6c c0 02 00 00 00 00 00 00 00 7c 0c 07 |w.-l.........|..|\
00000f70 af 9d 17 a1 c0 54 a1 6d 7c f7 ad 6c c0 02 00 00 |.....T.m|..l....|\
00000f80 00 00 00 00 00 87 31 73 12 93 20 a1 c0 df 42 7d |......1s.. ...B}|\
00000f90 0f a4 cf 6c c0 02 00 00 00 00 00 00 00 9b c4 dd |...l............|\
00000fa0 85 da 29 a1 c0 9d eb b9 8e 8d 60 6d c0 02 00 00 |..).......\`m....|\
00000fb0 00 00 00 00 00 c6 b3 95 bb 0c 26 a1 c0 cb 9f ed |..........&.....|\
00000fc0 1a cf cb 6c c0 02 00 00 00 00 00 00 00 4e d1 b2 |...l.........N..|\
00000fd0 93 28 13 a1 c0 48 e1 09 d7 59 e7 6c c0 02 00 00 |.(...H...Y.l....|\
00000fe0 00 00 00 00 00 5a a6 11 73 ed 18 a1 c0 a7 42 2a |.....Z..s.....B\*|\
00000ff0 af a7 37 6c c0 02 00 00 00 00 00 00 00 2e 16 53 |..7l...........S|\
00001000 fc ef 18 a1 c0 66 ab 8e 60 82 02 6d c0 02 00 00 |.....f..\`..m....|\
00001010 00 00 00 00 00 1a 08 f5 3c 52 1f a1 c0 0f f0 df |........4....w..>l....|\
00001190 00 00 00 00 00 d7 2d 7a 62 e8 2f a1 c0 25 5c d9 |......-zb./..%\\.|\
000011a0 23 32 23 6c c0 02 00 00 00 00 00 00 00 79 cb c2 |#2#l.........y..|\
000011b0 11 c4 3a a1 c0 60 76 f7 8f cc d1 6b c0 02 00 00 |..:..\`v....k....|\
000011c0 00 00 00 00 00 f0 3d 0b cd e3 3c a1 c0 8c 0c c7 |......=...<.....|\
000011d0 ff a7 44 6c c0 02 00 00 00 00 00 00 00 a2 db 70 |..Dl...........p|\
000011e0 bd c4 32 a1 c0 a7 de 35 e7 76 e9 6b c0 02 00 00 |..2....5.v.k....|\
000011f0 00 00 00 00 00 a8 b7 ef ec 15 2a a1 c0 97 b5 1c |..........\*.....|\
00001200 a3 c1 91 6b c0 02 00 00 00 00 00 00 00 76 87 8e |...k.........v..|\
00001210 c7 ae 35 a1 c0 de 42 53 fd c5 68 6b c0 02 00 00 |..5...BS..hk....|\
00001220 00 00 00 00 00 d7 bc 63 27 2a 2b a1 c0 4e 92 d3 |.......c'\*+..N..|\
00001230 12 bd 09 6b c0 02 00 00 00 00 00 00 00 ef fb 08 |...k............|\
00001240 9b 12 23 a1 c0 3f c3 a8 ce 25 5a 6b c0 02 00 00 |..#..?...%Zk....|\
00001250 00 00 00 00 00 db 4d 43 56 dd 28 a1 c0 72 0a 2e |......MCV.(..r..|\
00001260 07 c9 d5 6a c0 02 00 00 00 00 00 00 00 a1 15 b9 |...j............|\
00001270 73 54 25 a1 c0 53 61 b7 d6 fe aa 6a c0 02 00 00 |sT%..Sa....j....|\
00001280 00 00 00 00 00 ad 26 a7 bd 2e 28 a1 c0 29 8b f0 |......&...(..)..|\
00001290 8e eb 1b 6b c0 02 00 00 00 00 00 00 00 94 fc 04 |...k............|\
000012a0 61 42 23 a1 c0 d3 4b 1e 23 74 11 6b c0 02 00 00 |aB#...K.#t.k....|\
000012b0 00 00 00 00 00 ab cc 32 05 ca 23 a1 c0 0d ce 64 |.......2..#....d|\
000012c0 0a 44 e2 6a c0 02 00 00 00 00 00 00 00 cd ad 5d |.D.j...........\]|\
000012d0 b3 3b 25 a1 c0 bf 02 c5 ba c4 3d 6b c0 02 00 00 |.;%.......=k....|\
000012e0 00 00 00 00 00 27 e5 2c 80 67 26 a1 c0 b0 0f af |.....'.,.g&.....|\
000012f0 ad bb f2 6a c0 02 00 00 00 00 00 00 00 e8 eb d5 |...j............|\
00001300 a0 59 21 a1 c0 64 50 e1 cc 96 be 6a c0 02 00 00 |.Y!..dP....j....|\
00001310 00 00 00 00 00 ee 97 70 82 82 32 a1 c0 53 ac 89 |.......p..2..S..|\
00001320 ab 23 6e 6a c0 02 00 00 00 00 00 00 00 9a a1 f9 |.#nj............|\
00001330 0c e5 22 a1 c0 78 16 51 4b 83 e1 6b c0 02 00 00 |.."..x.QK..k....|\
00001340 00 00 00 00 00 c6 26 6b 94 83 1f a1 c0 87 54 87 |......&k......T.|\
00001350 53 7e e9 6b c0 02 00 00 00 00 00 00 00 c2 7b 25 |S~.k..........{%|\
00001360 71 52 21 a1 c0 a5 8e 3c 2f 21 b7 6b c0 02 00 00 |qR!....!.k....|\
00001370 00 00 00 00 00 d0 35 be fb 29 1d a1 c0 e6 10 a2 |......5..)......|\
00001380 20 44 c2 6b c0 02 00 00 00 00 00 00 00 c5 c7 b3 | D.k............|\
00001390 0c 78 26 a1 c0 91 34 b2 fd a2 79 6c c0 02 00 00 |.x&...4...yl....|\
000013a0 00 00 00 00 00 38 05 6a 12 be 14 a1 c0 52 0b b2 |.....8.j.....R..|\
000013b0 3e 37 e9 6a c0 02 00 00 00 00 00 00 00 87 5e 2b |>7.j..........^+|\
000013c0 e4 59 17 a1 c0 c0 8e 49 75 56 a5 6a c0 02 00 00 |.Y.....IuV.j....|\
000013d0 00 00 00 00 00 a7 c0 28 f7 e4 1d a1 c0 d1 04 99 |.......(........|\
000013e0 65 31 85 6b c0 02 00 00 00 00 00 00 00 e7 5b 2e |e1.k..........\[.|\
000013f0 a9 24 1e a1 c0 98 70 5a c4 12 ec 6a c0 02 05 00 |.$....pZ...j....|\
00001400 00 00 00 00 00 00 76 61 6c 75 65 04 00 00 00 00 |......value.....|\
00001410 00 00 f0 3f 00 00 00 00 00 00 20 40 00 00 00 00 |...?...... @....|\
00001420 00 00 24 40 00 00 00 00 00 00 18 40 00 00 00 00 |..$@.......@....|\
00001430 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001440 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001450 00 00 00 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
00001460 00 00 f0 3f 00 00 00 00 00 00 08 40 00 00 00 00 |...?.......@....|\
00001470 00 00 08 40 00 00 00 00 00 00 14 40 00 00 00 00 |...@.......@....|\
00001480 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001490 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
000014a0 00 00 10 40 00 00 00 00 00 00 10 40 00 00 00 00 |...@.......@....|\
000014b0 00 00 10 40 00 00 00 00 00 00 10 40 00 00 00 00 |...@.......@....|\
000014c0 00 00 10 40 00 00 00 00 00 00 10 40 00 00 00 00 |...@.......@....|\
000014d0 00 00 08 40 00 00 00 00 00 00 08 40 00 00 00 00 |...@.......@....|\
000014e0 00 00 08 40 00 00 00 00 00 00 10 40 00 00 00 00 |...@.......@....|\
000014f0 00 00 08 40 00 00 00 00 00 00 08 40 00 00 00 00 |...@.......@....|\
00001500 00 00 08 40 00 00 00 00 00 00 08 40 00 00 00 00 |...@.......@....|\
00001510 00 00 14 40 00 00 00 00 00 00 08 40 00 00 00 00 |...@.......@....|\
00001520 00 00 08 40 00 00 00 00 00 00 08 40 00 00 00 00 |...@.......@....|\
00001530 00 00 08 40 00 00 00 00 00 00 10 40 00 00 00 00 |...@.......@....|\
00001540 00 00 10 40 00 00 00 00 00 00 08 40 00 00 00 00 |...@.......@....|\
00001550 00 00 08 40 00 00 00 00 00 00 08 40 00 00 00 00 |...@.......@....|\
00001560 00 00 08 40 00 00 00 00 00 00 10 40 00 00 00 00 |...@.......@....|\
00001570 00 00 10 40 00 00 00 00 00 00 10 40 00 00 00 00 |...@.......@....|\
00001580 00 00 00 40 00 00 00 00 00 00 22 40 00 00 00 00 |...@......"@....|\
00001590 00 00 00 40 00 00 00 00 00 00 1c 40 00 00 00 00 |...@.......@....|\
000015a0 00 00 2a 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |..\*@.......?....|\
000015b0 00 00 28 40 00 00 00 00 00 00 10 40 00 00 00 00 |..(@.......@....|\
000015c0 00 00 3f 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |..?@.......?....|\
000015d0 00 00 f0 3f 00 00 00 00 00 00 31 40 00 00 00 00 |...?......1@....|\
000015e0 00 00 14 40 00 00 00 00 00 00 14 40 00 00 00 00 |...@.......@....|\
000015f0 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001600 00 00 20 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |.. @.......?....|\
00001610 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001620 00 00 00 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
00001630 00 00 00 40 00 00 00 00 00 00 08 40 00 00 00 00 |...@.......@....|\
00001640 00 00 00 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
00001650 00 00 f0 3f 00 00 00 00 00 00 00 40 00 00 00 00 |...?.......@....|\
00001660 00 00 f0 3f 00 00 00 00 00 00 08 40 00 00 00 00 |...?.......@....|\
00001670 00 00 00 40 00 00 00 00 00 00 08 40 00 00 00 00 |...@.......@....|\
00001680 00 00 08 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
00001690 00 00 00 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
000016a0 00 00 00 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
000016b0 00 00 00 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
000016c0 00 00 00 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
000016d0 00 00 f0 3f 00 00 00 00 00 00 00 40 00 00 00 00 |...?.......@....|\
000016e0 00 00 00 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
000016f0 00 00 00 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
00001700 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001710 00 00 f0 3f 00 00 00 00 00 00 00 40 00 00 00 00 |...?.......@....|\
00001720 00 00 08 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
00001730 00 00 00 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
00001740 00 00 08 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
00001750 00 00 f0 3f 00 00 00 00 00 00 08 40 00 00 00 00 |...?.......@....|\
00001760 00 00 f0 3f 00 00 00 00 00 00 00 40 00 00 00 00 |...?.......@....|\
00001770 00 00 f0 3f 00 00 00 00 00 00 00 40 00 00 00 00 |...?.......@....|\
00001780 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001790 00 00 f0 3f 00 00 00 00 00 00 08 40 00 00 00 00 |...?.......@....|\
000017a0 00 00 00 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
000017b0 00 00 f0 3f 00 00 00 00 00 00 22 40 00 00 00 00 |...?......"@....|\
000017c0 00 00 00 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
000017d0 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
000017e0 00 00 f0 3f 00 00 00 00 00 00 00 40 00 00 00 00 |...?.......@....|\
000017f0 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001800 00 00 18 40 00 00 00 00 00 00 28 40 00 00 00 00 |...@......(@....|\
00001810 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001820 00 00 35 40 00 00 00 00 00 00 33 40 00 00 00 00 |..5@......3@....|\
00001830 00 00 f0 3f 00 00 00 00 00 00 00 40 00 00 00 00 |...?.......@....|\
00001840 00 00 14 40 00 00 00 00 00 00 10 40 00 00 00 00 |...@.......@....|\
00001850 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001860 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001870 00 00 f0 3f 00 00 00 00 00 00 1c 40 00 00 00 00 |...?.......@....|\
00001880 00 00 1c 40 00 00 00 00 00 00 18 40 00 00 00 00 |...@.......@....|\
00001890 00 00 f0 3f 00 00 00 00 00 00 10 40 00 00 00 00 |...?.......@....|\
000018a0 00 00 2e 40 00 00 00 00 00 00 14 40 00 00 00 00 |...@.......@....|\
000018b0 00 00 18 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
000018c0 00 00 f0 3f 00 00 00 00 00 00 10 40 00 00 00 00 |...?.......@....|\
000018d0 00 00 00 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
000018e0 00 00 18 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
000018f0 00 00 14 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
00001900 00 00 f0 3f 00 00 00 00 00 00 22 40 00 00 00 00 |...?......"@....|\
00001910 00 00 31 40 00 00 00 00 00 00 2a 40 00 00 00 00 |..1@......\*@....|\
00001920 00 00 1c 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
00001930 00 00 f0 3f 00 00 00 00 00 00 18 40 00 00 00 00 |...?.......@....|\
00001940 00 00 08 40 00 00 00 00 00 00 14 40 00 00 00 00 |...@.......@....|\
00001950 00 00 14 40 00 00 00 00 00 00 18 40 00 00 00 00 |...@.......@....|\
00001960 00 00 00 40 00 00 00 00 00 00 10 40 00 00 00 00 |...@.......@....|\
00001970 00 00 08 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
00001980 00 00 f0 3f 00 00 00 00 00 00 14 40 00 00 00 00 |...?.......@....|\
00001990 00 00 28 40 00 00 00 00 00 00 14 40 00 00 00 00 |..(@.......@....|\
000019a0 00 00 10 40 00 00 00 00 00 00 24 40 00 00 00 00 |...@......$@....|\
000019b0 00 00 18 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
000019c0 00 00 22 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |.."@.......?....|\
000019d0 00 00 f0 3f 00 00 00 00 00 00 14 40 00 00 00 00 |...?.......@....|\
000019e0 00 00 1c 40 00 00 00 00 00 00 08 40 00 00 00 00 |...@.......@....|\
000019f0 00 00 14 40 00 00 00 00 00 00 14 40 00 00 00 00 |...@.......@....|\
00001a00 00 00 14 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
00001a10 00 00 14 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
00001a20 00 00 00 40 00 00 00 00 00 00 08 40 00 00 00 00 |...@.......@....|\
00001a30 00 00 08 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
00001a40 00 00 00 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
00001a50 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001a60 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001a70 00 00 08 40 00 00 00 00 00 00 14 40 00 00 00 00 |...@.......@....|\
00001a80 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001a90 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001aa0 00 00 f0 3f 00 00 00 00 00 00 18 40 00 00 00 00 |...?.......@....|\
00001ab0 00 00 18 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
00001ac0 00 00 f0 3f 00 00 00 00 00 00 00 40 00 00 00 00 |...?.......@....|\
00001ad0 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001ae0 00 00 10 40 00 00 00 00 00 00 10 40 00 00 00 00 |...@.......@....|\
00001af0 00 00 10 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
00001b00 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001b10 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001b20 00 00 f0 3f 00 00 00 00 00 00 00 40 00 00 00 00 |...?.......@....|\
00001b30 00 00 00 40 00 00 00 00 00 00 00 40 00 00 00 00 |...@.......@....|\
00001b40 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001b50 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001b60 00 00 00 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
00001b70 00 00 f0 3f 00 00 00 00 00 00 00 40 00 00 00 00 |...?.......@....|\
00001b80 00 00 00 40 00 00 00 00 00 00 08 40 00 00 00 00 |...@.......@....|\
00001b90 00 00 08 40 00 00 00 00 00 00 08 40 00 00 00 00 |...@.......@....|\
00001ba0 00 00 08 40 00 00 00 00 00 00 f0 3f 00 00 00 00 |...@.......?....|\
00001bb0 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001bc0 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001bd0 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001be0 00 00 f0 3f 00 00 00 00 00 00 f0 3f 00 00 00 00 |...?.......?....|\
00001bf0 00 00 f0 3f 00 00 00 00 00 00 f0 3f |...?.......?|\
00001bfc\
\`\`\`\
\
This file has an overall length of \`0x00001bfc == 7164\` bytes. In\
comparison, a \`graphml\` encoding results in \`37506\`\
bytes. Compressing both files with \[LZMA\](https://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Markov\_chain\_algorithm)\
results in \`2800\` and \`4192\` bytes, respectively. However, this\
difference (even when compressed) tends to increase, often considerably,\
for larger graphs. Furthermore the reading and writing in the \`gt\`\
format tends to be about an order of magnitude faster than \`graphml\`,\
and largely I/O-bound, instead of the latter, which is often\
CPU-bound. Here is an example for a somewhat larger graph:\
\
\`\`\`{eval-rst}\
.. testsetup:: gt\_format\
\
import sys\
import tempfile\
g = gt.collection.data\["pgp-strong-2009"\].copy()\
g.properties.clear()\
tmpdir = tempfile.mkdtemp()\
g.save("%s/pgp\_graph.xml" % tmpdir)\
if sys.version\_info >= (3,):\
g.save("%s/pgp\_graph.xml.xz" % tmpdir)\
g.save("%s/pgp\_graph.gt" % tmpdir)\
if sys.version\_info >= (3,):\
g.save("%s/pgp\_graph.gt.xz" % tmpdir)\
\`\`\`\
\
\`\`\`{eval-rst}\
.. doctest:: gt\_format\
\
>>> import timeit\
>>> g = gt.collection.data\["pgp-strong-2009"\]\
>>> g.properties.clear() # Use only topology for benchmark\
>>> timeit.Timer(lambda: g.save("/tmp/pgp\_graph.xml")).timeit(number=1) # doctest: +SKIP\
0.08416466903872788\
>>> timeit.Timer(lambda: g.save("/tmp/pgp\_graph.xml.xz")).timeit(number=1) # doctest: +SKIP\
14.706654848065227\
>>> timeit.Timer(lambda: g.save("/tmp/pgp\_graph.gt")).timeit(number=1) # doctest: +SKIP\
0.005980597110465169\
>>> timeit.Timer(lambda: g.save("/tmp/pgp\_graph.gt.xz")).timeit(number=1) # doctest: +SKIP\
0.43757575505878776\
>>> timeit.Timer(lambda: gt.load\_graph("/tmp/pgp\_graph.xml")).timeit(number=1) # doctest: +SKIP\
0.9056955680716783\
>>> timeit.Timer(lambda: gt.load\_graph("/tmp/pgp\_graph.xml.xz")).timeit(number=1) # doctest: +SKIP\
1.0840389159275219\
>>> timeit.Timer(lambda: gt.load\_graph("/tmp/pgp\_graph.gt")).timeit(number=1) # doctest: +SKIP\
0.0512137800687924\
>>> timeit.Timer(lambda: gt.load\_graph("/tmp/pgp\_graph.gt.xz")).timeit(number=1) # doctest: +SKIP\
0.07995201298035681\
>>> import subprocess\
>>> print(subprocess.check\_output("du -b /tmp/pgp\_graph\* | sort -n", shell=True).decode("utf-8")) # doctest: +SKIP\
395148 /tmp/pgp\_graph.gt.xz\
921619 /tmp/pgp\_graph.gt\
1010208 /tmp/pgp\_graph.xml.xz\
21324583 /tmp/pgp\_graph.xml\
\
\`\`\`
---