pyyeti.locate.index2slice

pyyeti.locate.index2slice(pv, strict=False)[source]

Convert index partition vector pv to a slice object

Parameters:
  • pv (1d ndarray) – The index partition vector to convert.

  • strict (bool; optional) – If False (the default) return pv unchanged if it cannot be converted to a slice. If True, raise ValueError if pv cannot be converted.

Returns:

Slice object or pv – If pv cannot be converted, output depends on strict (see above)

Raises:
  • ValueError – When pv is not 1d.

  • ValueError – When pv cannot be converted to a slice and strict is True

Examples

>>> import numpy as np
>>> from pyyeti.locate import index2slice
>>> pv = [3, 4, 5, 6]
>>> index2slice(pv)
slice(3, 7, 1)
>>> pv = [10, 7, 4, 1]
>>> index2slice(pv)
slice(10, None, -3)
>>> pv = [-1]
>>> index2slice(pv)
slice(-1, None, None)
>>> pv = np.array([0, 3, 5])
>>> index2slice(pv)
array([0, 3, 5]...)