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
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
<apll>
<table border="1" cellpadding="5" cellspacing="0" rules="none" summary="">
Z←L⍷R
<tr>
</apll>
  <td>
<p>
    <table border="0" cellpadding="5" cellspacing="0" summary="">
<br> <b>Find</b> looks for patterns <apll>R</apll> in <apll>L</apll>.
    <tr>
<br> It returns a simple boolean array with the same shape as <apll>L</apll>.
      <td valign="top"><apll>Z←L⍷R</apll></td>
<br> <br>
      <td></td>
<apll>L</apll> and <apll>R</apll> are arbitrary arrays.
      <td></td>
      <td>finds the matches of <apll>L</apll> in <apll>R</apll>.</td>
    </tr>
    </table>
  </td>
</tr>
<tr>
  <td><apll>L</apll> and <apll>R</apll> are arbitrary arrays of any rank, shape, or datatype.
But to be useful,
But to be useful,
the rank of <apll>R</apll>
<ul>
should not be more than the rank of <apll>L</apll>,
  <li>the rank of <apll>L</apll> should not be more than the rank of <apll>R</apll></li>
and both arguments should have the same type
  <li>the shape of <apll>L</apll> padded with enough leading <apll>1</apll>s to equal the rank of <apll>R</apll> should be less than or equal to the shape of <apll>R</apll></li>
(either both character or both numeric).
  <li>both arguments should have the same type (either both character or both numeric)</li>
<br> <br>
</ul>
If <apll>R</apll> is a scalar,
otherwise the result is all zero.</td>
then <apll>Z←L⍷R ←→ L∊R</apll>.
</tr>
<br/>
<tr>
If <apll>R</apll> is not a scalar,
  <td><apll>Z</apll> is a Boolean array of the same rank and shape as <apll>R</apll> where each <apll>1</apll> represents the upper left corner of a place in <apll>R</apll> of a match with <apll>L</apll>.
then it represents a contiguous pattern,
</td>
which may or may not be found in one or more places in <apll>L</apll>.
</tr>
<br> <br>
</table>
If the arguments are numeric,
then the result is sensitive to <apll>⎕CT</apll>.


<br> <br>
Examples:
<br> <br>
<apll>


<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L←3 8⍴'thirteenfourteenfifteen '
If <apll>L</apll> is a scalar, then <apll>L⍷R ←→ R∊L</apll>.
<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L
<br/> thirteen
<br/> fourteen
<br/> fifteen


<br> <br>
If <apll>L</apll> is not a scalar, then it represents a contiguous pattern,
<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L⍷'t'
which may or may not be found in one or more places in <apll>R</apll>.
<br/> 1 0 0 0 1 0 0 0
<br/> 0 0 0 0 1 0 0 0
<br/> 0 0 0 1 0 0 0 0


<br> <br>
If the arguments are numeric, then the result is sensitive to <apll>⎕CT</apll>.
<br/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; L⍷'teen'
<br/> 0 0 0 0 1 0 0 0
<br/> 0 0 0 0 1 0 0 0
<br/> 0 0 0 1 0 0 0 0


</apll>
For example:
<br> <br>
 
<apll><pre>
      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
      (2 4⍴'teen')⍷R
0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
</pre></apll>

Latest revision as of 22:28, 15 April 2018

Z←L⍷R finds the matches of L in R.
L and R are arbitrary arrays of any rank, shape, or datatype.

But to be useful,

  • the rank of L should not be more than the rank of R
  • the shape of L padded with enough leading 1s to equal the rank of R should be less than or equal to the shape of R
  • both arguments should have the same type (either both character or both numeric)
otherwise the result is all zero.
Z is a Boolean array of the same rank and shape as R where each 1 represents the upper left corner of a place in R of a match with L.


If L is a scalar, then 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.

For example:

      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
      (2 4⍴'teen')⍷R
0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0