Difference between revisions of "Index Of"

From NARS2000
Jump to navigationJump to search
 
(One intermediate revision by one other user not shown)
Line 13: Line 13:
 
</tr>
 
</tr>
 
<tr>
 
<tr>
   <td><apll>L</apll> is an array of rank &gt; 1.</td>
+
   <td><apll>L</apll> is an array of rank not equal 1.</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
Line 22: Line 22:
 
</tr>
 
</tr>
 
<tr>
 
<tr>
   <td>This feature extends dyadic iota to rank &gt; 1 left arguments.</td>
+
   <td>This feature extends dyadic iota to non-vector left arguments.</td>
 
</tr>
 
</tr>
 
<tr>
 
<tr>
   <td>This function is sensitive to <apll>⎕IO</apll>.</td>
+
   <td>This function is sensitive to <apll>⎕IO</apll> and <apll>⎕CT</apll>.</td>
 
</tr>
 
</tr>
 
</table>
 
</table>
Line 31: Line 31:
 
<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><pre>
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;M⍳'afg'</apll><br />
+
      M←2 3⍴'abcdef'
<apll>&nbsp;1 1&nbsp;&nbsp;2 3&nbsp;&nbsp;3 4</apll><br >
+
      M⍳'afg'
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;M[M⍳'af']</apll><br />
+
1 1 2 3 3 4
<apll>af</apll>
+
      M[M⍳'af']
 +
af
 +
      L←2 ⋄ ⎕FMT L⍳⍳3
 +
┌3──────────┐
 +
│┌0┐ ┌0┐ ┌0┐│
 +
││0│ │0│ │0││
 +
│└~┘ └~┘ └~┘2
 +
└∊──────────┘</pre></apll>
 +
 
 +
<p>Note that this extension preserves the identity <apll>R≡L[L⍳R]</apll> for all <apll>R⊆L</apll>.</p>
  
 
<p>This extension is implemented via an internal magic function:</p>
 
<p>This extension is implemented via an internal magic function:</p>
  
<apll>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Z←L #DydIota R;⎕IO;O</apll><br />
+
<apll><pre>
<apll>[1]&nbsp;&nbsp;&nbsp;O←⎕IO ⋄ ⎕IO←0</apll><br />
+
    ∇ Z←L #DydIota R;⎕IO;O
<apll>[2]&nbsp;&nbsp;&nbsp;Z←⊂[0] O+(1+⍴L)⊤(¯1↓,(1+⍴L)↑L)⍳R</apll><br />
+
[1]   O←⎕IO ⋄ ⎕IO←0
<apll>&nbsp;&nbsp;&nbsp;&nbsp;∇</apll>
+
[2]   Z←⊂[0] O+(1+⍴L)⊤(¯1↓,(1+⍴L)↑L)⍳R
 +
    ∇</pre></apll>

Latest revision as of 22:33, 15 April 2018

Z←L⍳R returns a nested array of indices suitable to indexing L.
L is an array of rank not equal 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 non-vector left arguments.
This function is sensitive to ⎕IO and ⎕CT.


For example, in origin-1

      M←2 3⍴'abcdef'
      M⍳'afg'
 1 1  2 3  3 4
      M[M⍳'af']
af
      L←2 ⋄ ⎕FMT L⍳⍳3
┌3──────────┐
│┌0┐ ┌0┐ ┌0┐│
││0│ │0│ │0││
│└~┘ └~┘ └~┘2
└∊──────────┘

Note that this extension preserves the identity R≡L[L⍳R] for all R⊆L.

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
    ∇