Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9be87aa

Browse files
committed
STY: Refactor concatenation of index array
1 parent 3f384aa commit 9be87aa

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/matplotlib/mlab.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3880,9 +3880,18 @@ def contiguous_regions(mask):
38803880
if not mask.size:
38813881
return []
38823882

3883+
# Find the indices of region changes, and correct offset
38833884
idx, = np.nonzero(mask[:-1] != mask[1:])
3884-
idx = np.concatenate((([0],) if mask[0] else ()) + (idx + 1,) +
3885-
(([len(mask)],) if mask[-1] else ()))
3885+
idx += 1
3886+
3887+
# Add first and/or last index if needed
3888+
if mask[0] or mask[-1]:
3889+
idx = (idx,)
3890+
if mask[0]:
3891+
idx = ([0],) + idx
3892+
if mask[-1]:
3893+
idx = idx + ([len(mask)],)
3894+
idx = np.concatenate(idx)
38863895

38873896
return list(zip(idx[::2], idx[1::2]))
38883897

0 commit comments

Comments
 (0)