Given I'm more APL than APL2:
x←(1 2)(3 4 5)(6 7 8 9)
y←(2 1) (3 1 2 1) (2 4)
I need an idiom to return essentially each y picking out of each x, so result would be:
2 1 5 3 4 3 7 9
I know that this works: x{⍺[⍵]}¨y but:
1. i don't really understand why y indexes 'each' x. IOW, if that works, i'd think x[y] should work.
Now, i came up with this bastardized solution: x[↓((,↑⍴¨y)/⍳⍴x),[1.1]↑,/y] but i have to believe there's a cleaner way. Can someone shed some light for me as to why the dfn works, and also perhaps offer something more elegant than my hacked up vers? thanks
1:1 partitioning a Vec question
-
- Posts: 94
- Joined: Sat Nov 28, 2009 3:12 pm
Re: 1:1 partitioning a Vec question
Hi!
Your second approach is using the Reach Index, i.e. all the indices reach the equivalent item from the original nested vector. You could rewrite the example e.g. as
The first approach could also be written with the Index function:
I recommend consulting the DyalogAPL manual for Indexing.
-wm
Your second approach is using the Reach Index, i.e. all the indices reach the equivalent item from the original nested vector. You could rewrite the example e.g. as
x[↑,/,(⍳⍴y)∘.,¨y]which might show the original idea in a little bit clearer way.
The first approach could also be written with the Index function:
(⊂¨y)⌷¨x
I recommend consulting the DyalogAPL manual for Indexing.
-wm
- Morten|Dyalog
- Posts: 460
- Joined: Tue Sep 09, 2008 3:52 pm
Re: 1:1 partitioning a Vec question
thanks guys.
1. in my hacked version, i failed to note that i'm playing with some large data sets and (reflexively) avoided using an outer product.
2. (⊂¨y)⌷¨x is what i was looking for. i figured squish quad or pick would be the key, but i had checked Mastering APL for the exact construct and "For now, we shall not try to extract more than one item from a vector; we need additional knowledge to do that" caught me. My bad.
1. in my hacked version, i failed to note that i'm playing with some large data sets and (reflexively) avoided using an outer product.
2. (⊂¨y)⌷¨x is what i was looking for. i figured squish quad or pick would be the key, but i had checked Mastering APL for the exact construct and "For now, we shall not try to extract more than one item from a vector; we need additional knowledge to do that" caught me. My bad.
- Morten|Dyalog
- Posts: 460
- Joined: Tue Sep 09, 2008 3:52 pm
Re: 1:1 partitioning a Vec question
drothman wrote:i failed to note that i'm playing with some large data sets
In that case, it may be worth noting that:
Code: Select all
y←1000⍴(2 1)(3 1 2 1)(2 4)
x←1000⍴(1 2)(3 4 5)(6 7 8 9)
cmpx '(∊x)[∊y++\¯1↓0,≢¨x]' '∊(⊂¨y)⌷¨x'
(∊x)[∊y++\¯1↓0,≢¨x] → 1.4E¯4 | 0% ⎕⎕⎕⎕⎕⎕⎕
∊(⊂¨y)⌷¨x → 2.3E¯4 | +63% ⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕⎕
That's in the unreleased version 16.0 with Marshall's speed-ups to ∊. In v15 the difference is only about 25-30%.