# [SciPy-user] Again on array manipulation

Nathan Bell wnbell@gmail....
Tue Jun 24 09:06:41 CDT 2008

```On Tue, Jun 24, 2008 at 8:12 AM, Lorenzo Isella
<lorenzo.isella@gmail.com> wrote:
>
> a=[15 23 44 78|11 77| 33 45 89| 56 99| 12 654 81]
>
> b=[10 10 10 10|40 40| 60 60 60| 22 22| 17 17 17]
>
> (the vertical bar is just a guide for the eye).
> No entry appears twice in a and no entry appears only once in b. I
> would like to chop off all the
> elements appearing more than twice in b and get rid of the
> corresponding elements in a, thus ending up with:

If b consists of only small integers, then I'd used bincount()

In [15]: from scipy import *

In [16]: a = array([15, 23, 44, 78, 11, 77, 33, 45, 89, 56, 99, 12, 654, 81])

In [17]: b = array([10, 10, 10, 10, 40, 40, 60, 60, 60, 22, 22, 17, 17, 17])

In [18]: mask = (bincount(b) <= 2)[b]

In [19]: print a[mask]
[11 77 56 99]

In [20]: print b[mask]
[40 40 22 22]

Otherwise, it depends on whether the repeated elements of b are
contiguous or not.

--
Nathan Bell wnbell@gmail.com
http://graphics.cs.uiuc.edu/~wnbell/
```