icicle
icicle

Reputation: 87

Using the each operator with the without function in APL

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.

Upvotes: 2

Views: 352

Answers (2)

Adám
Adám

Reputation: 7616

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).

Upvotes: 4

TessellatingHeckler
TessellatingHeckler

Reputation: 28983

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│ │
│ └───┘ └───┘ │
└∊────────────┘

Upvotes: 3

Related Questions