## 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: 95
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% ⎕⎕⎕⎕`