[NumPy-Tickets] [NumPy] #1576: numpy.ma.flatnotmasked_contiguous error in slice.stop values

NumPy Trac numpy-tickets@scipy....
Sun Aug 8 22:48:36 CDT 2010

```#1576: numpy.ma.flatnotmasked_contiguous error in slice.stop values
-----------------------------------+----------------------------------------
Reporter:  gdmcbain               |       Owner:  pierregm
Type:  defect                 |      Status:  new
Priority:  normal                 |   Milestone:  Unscheduled
Component:  numpy.ma               |     Version:  1.3.0
-----------------------------------+----------------------------------------
The function numpy.ma.flatnotmasked_contiguous returns slices which
miss the last element; for example, based on the example at

{{{
import numpy as np
a = np.arange (10)
am = np.ma.array (a, mask = (a < 3) | (a > 8) | (a == 5))
print am[segments[0]], am[segments[1]]
}}}

prints

the masked array: [-- -- -- 3 4 -- 6 7 8 --]
flatnotmasked_contiguous:  [slice(3, 4, None), slice(6, 8, None)]
[3] [6 7]

which isn't really what we're after; I would have expected [3 4] and
[6 7 8]. Compare the similarly named
matplotlib.mlab.contiguous_regions which does have the expected
behaviour (although its output format is different)

{{{
import matplotlib.mlab
segments1 = matplotlib.mlab.contiguous_regions (am)
print 'contiguous_regions:', segments1
print am[slice (*segments1[0])], am[slice (*segments1[1])]
}}}

which prints

contiguous_regions: [(3, 5), (6, 9)]
[3 4] [6 7 8]

--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1576>
NumPy <http://projects.scipy.org/numpy>
My example project
```