From 44341691f0b4c4bd6d670baef538595a128e4076 Mon Sep 17 00:00:00 2001 From: Rob McMullen Date: Sun, 6 Mar 2016 21:38:59 -0800 Subject: [PATCH] Added bool_to_ranges to convert numpy boolean result to list of ranges --- atrcopy/segments.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/atrcopy/segments.py b/atrcopy/segments.py index 116ebf4..32cd4ff 100755 --- a/atrcopy/segments.py +++ b/atrcopy/segments.py @@ -100,7 +100,11 @@ class DefaultSegment(object): def get_style_ranges(self, **kwargs): style_bits = self.get_style_bits(**kwargs) - w = np.where(self.style & style_bits)[0] + matches = (self.style & style_bits) > 0 + return self.bool_to_ranges(matches) + + def bool_to_ranges(self, matches): + w = np.where(matches == True)[0] # split into groups with consecutive numbers groups = np.split(w, np.where(np.diff(w) != 1)[0] + 1) ranges = []