## index function

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

### index function

`      +a←5 4 ⍴ ⍳20 1  2  3  4 5  6  7  8 9 10 11 1213 14 15 1617 18 19 20      a[2;]5 6 7 8      a[;3]3 7 11 15 19      2 ⌷ a5 6 7 8`

but how do you extract the 3rd column using the index function?
BenoitM

Posts: 4
Joined: Tue Jan 12, 2021 3:04 pm

### Re: index function

Extracting the 3rd column of a matrix (⎕IO=1)
`      3⌷[2]a    ⍝ Index fn w/ axis op (special syntax)3 7 11 15 19      3⌷⍤1⊣a    ⍝ Index fn w/ rank op3 7 11 15 19      a[;3]     ⍝ Bracket Indexing  3 7 11 15 19`

And...
`      COL←(⌷⍤1)      3 COL a3 7 11 15 19`
petermsiegel

Posts: 107
Joined: Thu Nov 11, 2010 11:04 pm

### Re: index function

In addition to what petermsiegel wrote, it is worth noting that if you are going to extract columns repeatedly, it may be worthwhile to transpose your matrix once.
`      a←?1000 1000⍴0      aT←⍉a      ]runtime -c 3⌷[2]a 3⌷⍤1⊢a a[;3] 3⌷aT                                                                    3⌷[2]a → 3.1E¯6 |   0% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕   3⌷⍤1⊢a → 2.8E¯6 |  -8% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕      a[;3]  → 2.6E¯6 | -16% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕         3⌷aT   → 2.9E¯7 | -91% ⎕⎕⎕⎕`

Posts: 105
Joined: Thu Jun 25, 2015 1:13 pm

### Re: index function

I was scratching my head over this until I realized that by employing the intermediate variable aT you meant "extract columns repeatedly from the SAME array".
`      a←?1000 1000⍴0      ]runtime -c 3⌷[2]a 3⌷⍤1⊢a a[;3] 3⌷⍉a                                                                        3⌷[2]a → 2.0E¯6 |       0%                                            3⌷⍤1⊢a → 2.0E¯6 |       0%                                            a[;3]  → 1.5E¯6 |     -25%                                            3⌷⍉a   → 2.3E¯3 | +118200%`

:-)
mwr0707

Posts: 12
Joined: Wed Oct 28, 2015 9:49 am

### Who is online

Users browsing this forum: No registered users and 0 guests