9
votes

I'm using the scipy ndimage modules and I'm using the find_objects function, which returns a slice object. Now i want to read this slice object and get the start and end indices from them. However, i can't find the way to do that.

fragments = ndimage.find_objects(labels)
print fragments[0][0]
> slice(0L, 832L, None)

How do i store the start and end indices as variables in my python code.

Any help will be appreciated. Thanks in advance.

1

1 Answers

15
votes

The members of a slice are start, step and stop:

Slice objects have read-only data attributes start, stop and step which merely return the argument values (or their default).


Thus as simple as:

>>> sl = slice(0L, 832L)
>>> sl
slice(0L, 832L, None)
>>> start = sl.start
>>> stop = sl.stop
>>> start, stop
(0L, 832L)