Functions used by more than one PyPhi module or class, or that might be of external use.

pyphi.utils.state_of(nodes, network_state)

Return the state-tuple of the given nodes.

pyphi.utils.all_states(n, holi=False)

Return all binary states for a system.

  • n (int) – The number of elements in the system.
  • holi (bool) – Whether to return the states in HOLI order instead of LOLI order.

tuple[int] – The next state of an n-element system, in LOLI order unless holi is True.


Make a NumPy array immutable.


Return a hash of a NumPy array.

pyphi.utils.eq(x, y)

Compare two values up to PRECISION.

pyphi.utils.combs(a, r)

NumPy implementation of itertools.combinations.

Return successive r-length combinations of elements in the array a.

  • a (np.ndarray) – The array from which to get combinations.
  • r (int) – The length of the combinations.

An array of combinations.

Return type:


pyphi.utils.comb_indices(n, k)

n-dimensional version of itertools.combinations.

  • a (np.ndarray) – The array from which to get combinations.
  • k (int) – The desired length of the combinations.

Indices that give the k-combinations of n elements.

Return type:



>>> n, k = 3, 2
>>> data = np.arange(6).reshape(2, 3)
>>> data[:, comb_indices(n, k)]
array([[[0, 1],
        [0, 2],
        [1, 2]],

       [[3, 4],
        [3, 5],
        [4, 5]]])
pyphi.utils.powerset(iterable, nonempty=False)

Generate the power set of an iterable.

Parameters:iterable (Iterable) – The iterable from which to generate the power set.
Returns:An chained generator over the power set.
Return type:generator


>>> ps = powerset(np.arange(2))
>>> print(list(ps))
[(), (0,), (1,), (0, 1)]
>>> ps = powerset(np.arange(2), nonempty=True)
>>> print(list(ps))
[(0,), (1,), (0, 1)]
pyphi.utils.load_data(directory, num)

Load numpy data from the data directory.

The files should stored in ../data/<dir> and named 0.npy, 1.npy, ... <num - 1>.npy.

Returns:A list of loaded data, such that list[i] contains the the contents of i.npy.
Return type:list