Difference between revisions of "Index Of"

From NARS2000
Jump to navigationJump to search
Line 1: Line 1:
<p>Dyadic iota (<apll>L⍳R</apll>) is extended to allow <apll>1&lt;⍴⍴L</apll>, returning a nested array of shape <apll>⍴R</apll> whose items are each integer vectors of length <apll>⍴⍴R</apll>, suitable for use as indices to <apll>L</apll>.</p>
+
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary="">
 
+
<tr>
 +
  <td>
 +
    <table border="0" cellpadding="5" cellspacing="0" summary="">
 +
    <tr>
 +
      <td><apll>Z←L⍳R</apll></td>
 +
      <td></td>
 +
      <td></td>
 +
      <td>returns a nested array of indices suitable to indexing <apll>L</apll>.</td>
 +
    </tr>
 +
    </table>
 +
  </td>
 +
</tr>
 +
<tr>
 +
  <td><apll>L</apll> is an array of rank &gt; 1.</td>
 +
</tr>
 +
<tr>
 +
  <td><apll>R</apll> is an arbitrary array.</td>
 +
</tr>
 +
<tr>
 +
  <td><apll>Z</apll> is a nested array of shape <apll>⍴R</apll> whose items are each integer vectors of length <apll>⍴⍴L</apll>, suitable for use as indices to <apll>L</apll>, except for where the item in <apll>R</apll> is not found in <apll>L</apll>, in which case the corresponding item in <apll>Z</apll> is <apll>⎕IO+⍴L</apll>.</td>
 +
</tr>
 +
<tr>
 +
  <td>This feature extends dyadic iota to rank &gt; 1 left arguments.</td>
 +
</tr>
 +
</table>
 +
<br />
 
<p>For example, in origin-1</p>
 
<p>For example, in origin-1</p>
  
 
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;M←2 3⍴'abcdef'</apll><br />
 
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;M←2 3⍴'abcdef'</apll><br />
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;M⍳'af'</apll><br />
+
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;M⍳'afg'</apll><br />
<apll>&nbsp;1 1&nbsp;&nbsp;2 3</apll><br >
+
<apll>&nbsp;1 1&nbsp;&nbsp;2 3&nbsp;&nbsp;3 4</apll><br >
 
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;M[M⍳'af']</apll><br />
 
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;M[M⍳'af']</apll><br />
 
<apll>af</apll>
 
<apll>af</apll>

Revision as of 19:41, 13 April 2008

Z←L⍳R returns a nested array of indices suitable to indexing L.
L is an array of rank > 1.
R is an arbitrary array.
Z is a nested array of shape ⍴R whose items are each integer vectors of length ⍴⍴L, suitable for use as indices to L, except for where the item in R is not found in L, in which case the corresponding item in Z is ⎕IO+⍴L.
This feature extends dyadic iota to rank > 1 left arguments.


For example, in origin-1

      M←2 3⍴'abcdef'
      M⍳'afg'
 1 1  2 3  3 4
      M[M⍳'af']
af

This extension is implemented via an internal magic function:

    ∇ Z←L #DydIota R;⎕IO;O
[1]   O←⎕IO ⋄ ⎕IO←0
[2]   Z←⊂[0] O+(1+⍴L)⊤(¯1↓,(1+⍴L)↑L)⍳R
    ∇