index function
4 posts
• Page 1 of 1
index function
+a←5 4 ⍴ ⍳20
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17 18 19 20
a[2;]
5 6 7 8
a[;3]
3 7 11 15 19
2 ⌷ a
5 6 7 8
but how do you extract the 3rd column using the index function?
- BenoitM
- Posts: 10
- Joined: Tue Jan 12, 2021 3:04 pm
Re: index function
Extracting the 3rd column of a matrix (⎕IO=1)
And...
3⌷[2]a ⍝ Index fn w/ axis op (special syntax)
3 7 11 15 19
3⌷⍤1⊣a ⍝ Index fn w/ rank op
3 7 11 15 19
a[;3] ⍝ Bracket Indexing
3 7 11 15 19
And...
COL←(⌷⍤1)
3 COL a
3 7 11 15 19
- petermsiegel
- Posts: 159
- 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% ⎕⎕⎕⎕
-
Adam|Dyalog - Posts: 143
- 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: 17
- Joined: Wed Oct 28, 2015 9:49 am
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group