pygsti.tools.slicetools.list_to_slice

Contents

pygsti.tools.slicetools.list_to_slice#

list_to_slice(lst, array_ok=False, require_contiguous=True)#

Returns a slice corresponding to a given list of (integer) indices, if this is possible.

If not, array_ok determines the behavior.

Parameters:
  • lst (list) – The list of integers to convert to a slice (must be contiguous if require_contiguous == True).

  • array_ok (bool, optional) – If True, an integer array (of type numpy.ndarray) is returned when lst does not correspond to a single slice. Otherwise, an AssertionError is raised.

  • require_contiguous (bool, optional) – If True, then lst will only be converted to a contiguous (step=1) slice, otherwise either a ValueError is raised (if array_ok is False) or an array is returned.

Return type:

numpy.ndarray or slice