Using the each operator with the without function in APL

Viewed 274

I have a nested array with the following data:

┌→────────────────┐
│ ┌→────┐ ┌→────┐ │
│ │ABC12│ │DEF34│ │
│ └─────┘ └─────┘ │
└∊────────────────┘

I would like to remove the numbers from each, so that it looks like this:

┌→────────────┐
│ ┌→──┐ ┌→──┐ │
│ │ABC│ │DEF│ │
│ └───┘ └───┘ │
└∊────────────┘

I tried using the without function (~) with the each operator (¨) and a right argument of '0123456789' but I get a length error. I also tried putting each number in its own array like this:

┌→────────────────────────────────────────┐
│ ┌→┐ ┌→┐ ┌→┐ ┌→┐ ┌→┐ ┌→┐ ┌→┐ ┌→┐ ┌→┐ ┌→┐ │
│ │0│ │1│ │2│ │3│ │4│ │5│ │6│ │7│ │8│ │9│ │
│ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ └─┘ │
└∊────────────────────────────────────────┘

but this too resulted in a length error. Any help would be appreciated.

2 Answers

What you are looking for is set-subtracting ("without-ing") the entire set of digits (⎕D) from each. So we enclose the digit set to act on it as a whole:

      'ABC12' 'DEF34'~¨⊂⎕D
┌→────────────┐
│ ┌→──┐ ┌→──┐ │
│ │ABC│ │DEF│ │
│ └───┘ └───┘ │
└∊────────────┘

Try it online!

Notice how this very much reads like what you want:

Your data ('ABC12' 'DEF34') without (~) each (¨) of the whole () set of digits (⎕D).

Assuming Dyalog APL, you could try a direct-function that removes digits (⎕D) from strings, applied to each string in your array, e.g.

      yourData
┌→────────────────┐
│ ┌→────┐ ┌→────┐ │
│ │ABC12│ │DEF34│ │
│ └─────┘ └─────┘ │
└∊────────────────┘
      {⍵~⎕D}¨yourData
┌→────────────┐
│ ┌→──┐ ┌→──┐ │
│ │ABC│ │DEF│ │
│ └───┘ └───┘ │
└∊────────────┘
Related