Find: Difference between revisions

From NARS2000
Jump to navigationJump to search
(Created page with "<apll> Z←L⍷R </apll> <p> <br> <b>Find</b> looks for patterns <apll>R</apll> in <apll>L</apll>. <br> It returns a simple boolean array with the same shape as <apll>L</apll>...")
 
No edit summary
Line 3: Line 3:
</apll>
</apll>
<p>
<p>
<br> <b>Find</b> looks for patterns <apll>R</apll> in <apll>L</apll>.
<br> <b>Find</b> looks for patterns <apll>L</apll> in <apll>R</apll>.
<br> It returns a simple boolean array with the same shape as <apll>L</apll>.
<br> It returns a simple boolean array with the same shape as <apll>R</apll>.
<br> <br>
<br> <br>
<apll>L</apll> and <apll>R</apll> are arbitrary arrays.
<apll>L</apll> and <apll>R</apll> are arbitrary arrays.
But to be useful,
But to be useful,
the rank of <apll>R</apll>
the rank of <apll>L</apll>
should not be more than the rank of <apll>L</apll>,
should not be more than the rank of <apll>R</apll>,
and both arguments should have the same type
and both arguments should have the same type
(either both character or both numeric).
(either both character or both numeric).
<br> <br>
<br> <br>
If <apll>R</apll> is a scalar,
If <apll>L</apll> is a scalar,
then <apll>Z←L⍷R ←→ L∊R</apll>.
then <apll>Z←L⍷R ←→ R∊L</apll>.
<br/>
<br/>
If <apll>R</apll> is not a scalar,
If <apll>L</apll> is not a scalar,
then it represents a contiguous pattern,
then it represents a contiguous pattern,
which may or may not be found in one or more places in <apll>L</apll>.
which may or may not be found in one or more places in <apll>R</apll>.
<br> <br>
<br> <br>
If the arguments are numeric,
If the arguments are numeric,
Line 28: Line 28:
<apll>
<apll>


<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L←3 8⍴'thirteenfourteenfifteen '
<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R←3 8⍴'thirteenfourteenfifteen '
<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L
<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; R
<br/> thirteen
<br/> thirteen
<br/> fourteen
<br/> fourteen
Line 35: Line 35:


<br> <br>
<br> <br>
<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L⍷'t'
<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 't'⍷R
<br/> 1 0 0 0 1 0 0 0
<br/> 1 0 0 0 1 0 0 0
<br/> 0 0 0 0 1 0 0 0
<br/> 0 0 0 0 1 0 0 0
Line 41: Line 41:


<br> <br>
<br> <br>
<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L⍷'teen'
<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'teen'⍷R
<br/> 0 0 0 0 1 0 0 0
<br/> 0 0 0 0 1 0 0 0
<br/> 0 0 0 0 1 0 0 0
<br/> 0 0 0 0 1 0 0 0

Revision as of 10:51, 4 December 2016

Z←L⍷R


Find looks for patterns L in R.
It returns a simple boolean array with the same shape as R.

L and R are arbitrary arrays. But to be useful, the rank of L should not be more than the rank of R, and both arguments should have the same type (either both character or both numeric).

If L is a scalar, then Z←L⍷R ←→ R∊L.
If L is not a scalar, then it represents a contiguous pattern, which may or may not be found in one or more places in R.

If the arguments are numeric, then the result is sensitive to ⎕CT.

Examples:


       R←3 8⍴'thirteenfourteenfifteen '
       R
thirteen
fourteen
fifteen


       't'⍷R
1 0 0 0 1 0 0 0
0 0 0 0 1 0 0 0
0 0 0 1 0 0 0 0


       'teen'⍷R
0 0 0 0 1 0 0 0
0 0 0 0 1 0 0 0
0 0 0 1 0 0 0 0