Question

I have the data in the following structures:

Nums←56 66 19 37 44 20 18 23 68 70 82

A←(⍳¨(3≤⍳4)/⍳4)
┌→────┬───────┐
│1 2 3│1 2 3 4│
└~───→┴~─────→┘

What I want to do is create another nested array that would have elements with values from Nums, selected using indexes from A, looking like that:

┌→───────┬───────────┐
│56 66 19│56 66 19 37│
└~──────→┴~─────────→┘

Then I want to perform operations on every element of my array but I think I know how to go from there. How do I create such array in APL?

Was it helpful?

Solution

How about

(⊂Nums){⍺[⍵]}¨A

and you can then go ahead and appy youf fn:

(⊂Nums){fn ⍺[⍵]}¨A

OTHER TIPS

Here's another way to structure the result

      A⌷¨¨⊂⊂Nums
56 66 19  56 66 19 37

In NARS2000, easy:

  Nums←56 66 19 37 44 20 18 23 68 70 82
  A←(⍳3)(⍳4)     
  ⎕fmt A
┌2──────────────────┐
│┌3─────┐ ┌4───────┐│
││ 1 2 3│ │ 1 2 3 4││
│└~─────┘ └~───────┘2
└∊──────────────────┘
  ⎕fmt {Nums[⍵]}¨¨A
┌2─────────────────────────┐
│┌3────────┐ ┌4───────────┐│
││ 56 66 19│ │ 56 66 19 37││
│└~────────┘ └~───────────┘2
└∊─────────────────────────┘
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top