Indices: Difference between revisions
From NARS2000
Jump to navigationJump to search
Sudleyplace (talk | contribs) No edit summary |
Sudleyplace (talk | contribs) No edit summary |
||
| Line 31: | Line 31: | ||
<p>For example, in origin-0</p> | <p>For example, in origin-0</p> | ||
<apll> | <apll><pre> | ||
0 0 0 | ⍸,3 | ||
0 0 0 | |||
1 | ⍬⍬⍬≡⍸3 ⍝ for scalar S, ⍸S ←→ S⍴⊂⍬ as per the definition R/⍳⍴R | ||
1 | |||
1 | ⍬≡⍸⍬ | ||
1 | |||
0 2 3 4 6 | ⍸1 0 1 1 1 0 1 | ||
0 2 3 4 6 | |||
3 6 10 | ⍸'Now is the time'=' ' | ||
3 6 10 | |||
0 0 1 1 1 2 2 2 2 | ⍸2 3 4 | ||
0 0 1 1 1 2 2 2 2 | |||
⍸⎕←2 3⍴⍳4 | |||
0 1 2 | |||
3 0 1 | |||
0 1 0 2 0 2 1 0 1 0 1 0 1 2 | |||
⍸1 2 3⍴⍳4 | |||
0 0 1 0 0 2 0 0 2 0 1 0 0 1 0 0 1 0 0 1 2 | |||
[1] | ∇ Z←(Txt Rep) txtrep Z;a | ||
[2] | [1] ⍝ Replace Txt in Z with Rep. | ||
[3] | [2] :Assert 2=⍴⍴Z ⋄ :Assert (⍴Txt)≡⍴Rep | ||
[4] | [3] a←⍸Txt⍷Z | ||
[4] Z[⊃⊃¨,¨/¨a+⊂0(0..¯1+⍴Txt)]←((⍴a),⍴Rep)⍴Rep | |||
∇ | |||
Who is the ti | 'Now' 'Who' txtrep 4 13⍴'Now is the time...' | ||
me...Who is t | Who is the ti | ||
he time...Who | me...Who is t | ||
he time...Who | |||
is the time.</pre></apll> | |||
Latest revision as of 17:49, 15 April 2018
|
||||
| R is a simple array of non-negative integers. | ||||
| For vector R, Z is an integer vector. For all other ranks of R, Z is a nested vector of integer vectors. In both case the length of Z is +/,R. | ||||
| For scalars or vectors, the result is equivalent to R/⍳⍴R which encapsulates a very common idiom in one symbol. | ||||
| For higher rank arrays, the result extends to produce a nested vector of vectors of the indices of all the positive integer elements of R replicated as per the corresponding value in R. | ||||
| This function is sensitive to ⎕IO. |
For example, in origin-0
⍸,3
0 0 0
⍬⍬⍬≡⍸3 ⍝ for scalar S, ⍸S ←→ S⍴⊂⍬ as per the definition R/⍳⍴R
1
⍬≡⍸⍬
1
⍸1 0 1 1 1 0 1
0 2 3 4 6
⍸'Now is the time'=' '
3 6 10
⍸2 3 4
0 0 1 1 1 2 2 2 2
⍸⎕←2 3⍴⍳4
0 1 2
3 0 1
0 1 0 2 0 2 1 0 1 0 1 0 1 2
⍸1 2 3⍴⍳4
0 0 1 0 0 2 0 0 2 0 1 0 0 1 0 0 1 0 0 1 2
∇ Z←(Txt Rep) txtrep Z;a
[1] ⍝ Replace Txt in Z with Rep.
[2] :Assert 2=⍴⍴Z ⋄ :Assert (⍴Txt)≡⍴Rep
[3] a←⍸Txt⍷Z
[4] Z[⊃⊃¨,¨/¨a+⊂0(0..¯1+⍴Txt)]←((⍴a),⍴Rep)⍴Rep
∇
'Now' 'Who' txtrep 4 13⍴'Now is the time...'
Who is the ti
me...Who is t
he time...Who
is the time.