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

module documentation

Utility functions that cannot be categorised anywhere else.

Class | `multidict` |
A dictionary-like object that is customized to deal with multiple values for the same key. |

Function | `consecutive_pairs` |
Returns consecutive pairs of items from the given iterable. |

Function | `dbl_epsilon` |
Approximates the machine epsilon value for doubles. |

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 | `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 | `_is_running_in_ipython` |
Internal function that determines whether igraph is running inside IPython or not. |

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)]

@contextmanager

def named_temporary_file(*args, **kwds):

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]

Parameters | |

values | Undocumented |

out_range | the range of output values |

in_range | the range of the input values; this is the range that is mapped
to out_range. None means to use the minimum and maximum of
the input, respectively. |

clamp | specifies what to do when an input value falls outside in_range.
True means to clamp the value to the bounds of in_range,
False means not to clamp. |

scale | an optional transformation to perform on the input values before mapping them to the output range. |

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