Find

From NARS2000
Jump to: navigation, search
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