Index Of: Difference between revisions

From NARS2000
Jump to navigationJump to search
(New page: <p>Dyadic iota (<apll>L⍳R</apll>) is extended to allow <apll>1<⍴⍴L</apll>, returning a nested array of shape <apll>⍴R</apll> whose items are each integer vectors of length <apll...)
 
No edit summary
Line 11: Line 11:
<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 F R;⎕IO;O</apll><br />
<apll>&nbsp;&nbsp;&nbsp;&nbsp;∇&nbsp;Z←L #DydIota R;⎕IO;O</apll><br />
<apll>[1]&nbsp;&nbsp;&nbsp;O←⎕IO ⋄ ⎕IO←0</apll><br />
<apll>[1]&nbsp;&nbsp;&nbsp;O←⎕IO ⋄ ⎕IO←0</apll><br />
<apll>[2]&nbsp;&nbsp;&nbsp;Z←⊂[0] O+(1+⍴L)⊤(¯1↓,(1+⍴L)↑L)⍳R</apll><br />
<apll>[2]&nbsp;&nbsp;&nbsp;Z←⊂[0] O+(1+⍴L)⊤(¯1↓,(1+⍴L)↑L)⍳R</apll><br />
<apll>&nbsp;&nbsp;&nbsp;&nbsp;∇</apll>
<apll>&nbsp;&nbsp;&nbsp;&nbsp;∇</apll>

Revision as of 21:35, 10 April 2008

Dyadic iota (L⍳R) is extended to allow 1<⍴⍴L, returning a nested array of shape ⍴R whose items are each integer vectors of length ⍴⍴R, suitable for use as indices to L.

For example, in origin-1

      M←2 3⍴'abcdef'
      M⍳'af'
 1 1  2 3
      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
    ∇