1:1 partitioning a Vec question
Posted: Fri Feb 03, 2017 2:37 pm
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
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