python-igraph API reference

List of all classes, functions and methods in python-igraph

module documentation

Utility functions that cannot be categorised anywhere else.

Variable __docformat__ Undocumented
Variable __license__ Undocumented
Function named_temporary_file Context manager that creates a named temporary file and returns its name.
Function numpy_to_contiguous_memoryview Converts a NumPy array or matrix into a contiguous memoryview object that is suitable to be forwarded to the Graph constructor.
Function rescale Rescales a list of numbers into a given range.
Function str_to_orientation Tries to interpret a string as an orientation value.
Function consecutive_pairs Returns consecutive pairs of items from the given iterable.
Class multidict A dictionary-like object that is customized to deal with multiple values for the same key.
Function safemax Safer variant of ``max()`` that returns a default value if the iterable is empty.
Function safemin Safer variant of ``min()`` that returns a default value if the iterable is empty.
Function dbl_epsilon Approximates the machine epsilon value for doubles.
Function _is_running_in_ipython Internal function that determines whether igraph is running inside IPython or not.
__docformat__ =

Undocumented

(type: str)
__license__ =

Undocumented

(type: str)
def _is_running_in_ipython():

Internal function that determines whether igraph is running inside IPython or not.

@contextmanager
def named_temporary_file(*args, **kwds):

Context manager that creates a named temporary file and returns its name.

All parameters are passed on to ``tempfile.mkstemp``, see its documentation for more info.

def numpy_to_contiguous_memoryview(obj):

Converts a NumPy array or matrix into a contiguous memoryview object that is suitable to be forwarded to the Graph constructor.

This is used internally to allow us to use a NumPy array or matrix directly when constructing a Graph.

def rescale(values, out_range=(0.0, 1.0), in_range=None, clamp=False, scale=None):

Rescales a list of numbers into a given range.

`out_range` gives the range of the output values; by default, the minimum of the original numbers in the list will be mapped to the first element in the output range and the maximum will be mapped to the second element. Elements between the minimum and maximum values in the input list will be interpolated linearly between the first and second values of the output range.

`in_range` may be used to override which numbers are mapped to the first and second values of the output range. This must also be a tuple, where the first element will be mapped to the first element of the output range and the second element to the second.

If `clamp` is ``True``, elements which are outside the given `out_range` after rescaling are clamped to the output range to ensure that no number will be outside `out_range` in the result.

If `scale` is not ``None``, it will be called for every element of `values` and the rescaling will take place on the results instead. This can be used, for instance, to transform the logarithm of the original values instead of the actual values. A typical use-case is to map a range of values to color identifiers on a logarithmic scale. Scaling also applies to the `in_range` parameter if present.

Examples:

>>> rescale(range(5), (0, 8))
[0.0, 2.0, 4.0, 6.0, 8.0]
>>> rescale(range(5), (2, 10))
[2.0, 4.0, 6.0, 8.0, 10.0]
>>> rescale(range(5), (0, 4), (1, 3))
[-2.0, 0.0, 2.0, 4.0, 6.0]
>>> rescale(range(5), (0, 4), (1, 3), clamp=True)
[0.0, 0.0, 2.0, 4.0, 4.0]
>>> rescale([0]*5, (1, 3))
[2.0, 2.0, 2.0, 2.0, 2.0]
>>> from math import log10
>>> rescale([1, 10, 100, 1000, 10000], (0, 8), scale=log10)
[0.0, 2.0, 4.0, 6.0, 8.0]
>>> rescale([1, 10, 100, 1000, 10000], (0, 4), (10, 1000), scale=log10)
[-2.0, 0.0, 2.0, 4.0, 6.0]
def str_to_orientation(value, reversed_horizontal=False, reversed_vertical=False):

Tries to interpret a string as an orientation value.

The following basic values are understood: ``left-right``, ``bottom-top``, ``right-left``, ``top-bottom``. Possible aliases are:

  • ``horizontal``, ``horiz``, ``h`` and ``lr`` for ``left-right``
  • ``vertical``, ``vert``, ``v`` and ``tb`` for top-bottom.
  • ``lr`` for ``left-right``.
  • ``rl`` for ``right-left``.

``reversed_horizontal`` reverses the meaning of ``horizontal``, ``horiz`` and ``h`` to ``rl`` (instead of ``lr``); similarly, ``reversed_vertical`` reverses the meaning of ``vertical``, ``vert`` and ``v`` to ``bt`` (instead of ``tb``).

Returns one of ``lr``, ``rl``, ``tb`` or ``bt``, or throws ``ValueError`` if the string cannot be interpreted as an orientation.

def consecutive_pairs(iterable, circular=False):

Returns consecutive pairs of items from the given iterable.

When `circular` is ``True``, the pair consisting of the last and first elements is also returned.

Example:

>>> list(consecutive_pairs(range(5)))
[(0, 1), (1, 2), (2, 3), (3, 4)]
>>> list(consecutive_pairs(range(5), circular=True))
[(0, 1), (1, 2), (2, 3), (3, 4), (4, 0)]
>>> list(consecutive_pairs([]))
[]
>>> list(consecutive_pairs([], circular=True))
[]
>>> list(consecutive_pairs([0]))
[]
>>> list(consecutive_pairs([0], circular=True))
[(0, 0)]
def safemax(iterable, default=0):

Safer variant of ``max()`` that returns a default value if the iterable is empty.

Example:

>>> safemax([-5, 6, 4])
6
>>> safemax([])
0
>>> safemax((), 2)
2
def safemin(iterable, default=0):

Safer variant of ``min()`` that returns a default value if the iterable is empty.

Example:

>>> safemin([-5, 6, 4])
-5
>>> safemin([])
0
>>> safemin((), 2)
2
def dbl_epsilon():

Approximates the machine epsilon value for doubles.

API Documentation for python-igraph, generated by pydoctor 21.2.2 at 2021-03-26 11:21:53.