0

Does someone know how to remove sinlge 1s from a bit mask using APLX? Example: 1 0 1 1 1 0 0 1 0 1 to 0 0 1 1 1 0 0 0 0 0

Hints greatly appreciated.

  • I think it is considered good form to mark a correct answer as correct. If you don't, people might stop answering your questions. It looks like Tobia has answered two of your questions so far. – Paul Mansour Mar 10 '14 at 23:04

2 Answers2

1

This is one way:

      b←1 0 1 1 1 0 0 1 0 1
      1↓e∧(¯1⌽e)∨1⌽e←0,b
0 0 1 1 1 0 0 0 0 0

It gives an 1 if there is an 1 in the original vector, either followed or preceded by 1.

Tobia
  • 17,856
  • 6
  • 74
  • 93
0

Here is one way. First, use the find function to locate all occurrances of 2 consecutive 1's, then use a shift and compare technique to extend all the runs of 1's by 1:

      a←1 0 1 1 1 0 0 1 0 1
      b←1 1⍷a
      b
0 0 1 1 0 0 0 0 0 0
      b∨0,¯1↓b
0 0 1 1 1 0 0 0 0 0
Paul Mansour
  • 1,436
  • 9
  • 11