Search code examples
arraysmap-functionaplset-differencedyalog

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.


Solution

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