pwtools.common.toslice¶
- pwtools.common.toslice(val)[source]¶
A simple wrapper around numpy.s_() taking strings as argument. Convert strings representing Python/numpy slice to slice objects.
- Parameters:
val (string)
Examples
‘3’ -> 3 ‘3:’ -> slice(3, None, None) ‘-2:’ -> slice(-2, None, None) ‘3:7’ -> slice(3, 7, None) ‘3:7:2’ -> slice(3, 7, 2) ‘3::2’ -> slice(3, None, 2) ‘::2’ -> slice(None, None, 2) ‘::-1’ -> slice(None, None, -1)
>>> import numpy as np >>> np.s_[1:5] slice(1, 5, None) >>> toslice('1:5') slice(1, 5, None)