Array Lookup: Difference between revisions

From NARS2000
Jump to navigationJump to search
(Created page with "<table border="1" cellpadding="5" cellspacing="0" rules="none" summary=""> <tr> <td> <table border="0" cellpadding="5" cellspacing="0" summary=""> <tr> <td val...")
 
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 7: Line 7:
       <td></td>
       <td></td>
       <td></td>
       <td></td>
       <td>returns a simple integer vector identical to <apll>(⊂⍤(¯1+⍴⍴L) L)⍳⊂⍤(¯1+⍴⍴L) R</apll>.</td>
       <td>returns a simple integer vector identical to <apll>(⊂⍤¯1 L)⍳⊂⍤(¯1+⍴⍴L) R</apll>.</td>
     </tr>
     </tr>
     </table>
     </table>
Line 16: Line 16:
</tr>
</tr>
<tr>
<tr>
   <td><apll>Z</apll> is an integer vector of length <apll>1↑⍴R</apll>.</td>
   <td><apll>Z</apll> is an array of rank <apll>0⌈1+(⍴⍴R)-⍴⍴L</apll> and shape <apll>(1-⍴⍴L)↓⍴R</apll>.</td>
</tr>
</tr>
<tr>
<tr>
   <td>For matrices, the result is equivalent to <apll>(⊂[2] L)⍳⊂[2] R</apll> which encapsulates a common idiom in one symbol.</td>
   <td>For matrices, the result is equivalent to <apll>(⊂[2] L)⍳⊂[2] R</apll> (lookup the rows of one array in another) which encapsulates a common idiom in one symbol.</td>
</tr>
</tr>
<tr>
<tr>
   <td>For higher rank arrays, the arguments are enclosed to become vectors of subarrays and then the usual lookup produces the final result.</td>
   <td>For higher rank arrays, the arguments are enclosed to become vectors of subarrays and then the usual lookup produces the final result.</td>
</tr>
<tr>
  <td>This function is sensitive to both <apll>⎕IO</apll> and <apll>⎕CT</apll>.</td>
</tr>
</tr>
</table>
</table>
Line 28: Line 31:
<p>For example, in origin-1</p>
<p>For example, in origin-1</p>


<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⎕←L←6 4⍴'DinaDickJohnJaneSue Mary'<br />
<apll><pre>
Dina<br />
      ⎕←L←6 4⍴'DinaDickJohnJaneSue Mary
Dick<br />
Dina
John<br />
Dick
Jane<br />
John
Sue <br />
Jane
Mary<br />
Sue  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;⎕←R←3 4⍴'JaneBob Sue '<br />
Mary
Jane<br />
      ⎕←R←3 4⍴'JaneBob Sue '<br />
Bob <br />
Jane
Sue <br />
Bob  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;L⍸R<br />
Sue
4 7 5</apll>
      L⍸R
4 7 5</pre></apll>
 
<p>This function was suggested by the language designers of Dyalog APL.</p>

Latest revision as of 20:16, 15 April 2018

Z←L⍸R returns a simple integer vector identical to (⊂⍤¯1 L)⍳⊂⍤(¯1+⍴⍴L) R.
L and R are arbitrary arrays.
Z is an array of rank 0⌈1+(⍴⍴R)-⍴⍴L and shape (1-⍴⍴L)↓⍴R.
For matrices, the result is equivalent to (⊂[2] L)⍳⊂[2] R (lookup the rows of one array in another) which encapsulates a common idiom in one symbol.
For higher rank arrays, the arguments are enclosed to become vectors of subarrays and then the usual lookup produces the final result.
This function is sensitive to both ⎕IO and ⎕CT.


For example, in origin-1

      ⎕←L←6 4⍴'DinaDickJohnJaneSue Mary
Dina
Dick
John
Jane
Sue 
Mary
      ⎕←R←3 4⍴'JaneBob Sue '
Jane Bob Sue L⍸R 4 7 5

This function was suggested by the language designers of Dyalog APL.