Naming Conventions

Scalar

Vector

Matrix

Any
rank

Non-
scalar

Boolean

BS

BV

BM

BA

BN

Integer

IS

IV

IM

IA

IN

Float

FS

FV

FM

FA

FN

Numeric

NS

NV

NM

NA

NN

Character

CS

CV

CM

CA

CN

Enclosed
vector

ES

EV

EM

EA

EN

enclosed
Text vector

TS

TV

TM

TA

TN

Simple

SS

SV

SM

SA

SN

Any

AS

AV

AM

AA

AN

phrase e.g.: .X...Y. ⍝ X←BS; Y←IV

combinations: use ISV for Integer scalarvector

B3, I4 &c. to specify higher ranks.

Open full technical reference

FindRowsInMatrix

Returns an integer vector reporting how many times each row in AM1 is found in AM2:

      +/AM1^.=⍉AM2

Every row in AM1 is supposed to be unique. The number of columns in both matrices must be the same.

Examples

      ⎕FX ⍕2 1⍴'r←AM1 FindRowsInMatrix AM2' 'r←+/AM1^.=⍉AM2' 
      AM1←⊃'Barak Obama' 'George Bush' 'Bill Clinton' 'Ronald Reagan' 'Gerald Ford' 'John Kennedy'
      AM2←AM1[2 2 5;]
      AM1 FindRowsInMatrix AM2
0 0 2 0 0 1

Compatibility

Checked with: APLX, NARS2000, Dyalog

Remarks

You might want to make sure that a vector provided as right argument is automatically turned into a matrix. You can do so by making use of the phrase EnforceMatrix.

Test Cases

Show test cases

Test
 ⎕IO←0      ⍝ You may change this; however, zero IS the default in the Phrasebook
⍝⎕ML←3      ⍝ Enable this line in Dyalog APL if appropriate
  ⎕FX ⍕2 1⍴'r←AM1 FindRowsInMatrix AM2' 'r←+/AM1^.=⍉AM2'    ⍝ This will work in any APL dialect
⍝ ---- Start Test cases (do not delete this!)
1 0 0 1 ≡ (⊃'Barak Obama' 'George Bush' 'Bill Clinton' 'Ronald Reagan') FindRowsInMatrix  ⊃'Ronald Reagan' 'Barak Obama'
0 1 0 2 ≡ (⊃'Barak Obama' 'George Bush' 'Bill Clinton' 'Ronald Reagan') FindRowsInMatrix ⊃'Ronald Reagan' 'George Bush' 'Ronald Reagan'
⍬≡(0 13⍴' ') FindRowsInMatrix ,[-.5]'Ronald Reagan'
0 0 0 3 0 0≡(⊃6/¨⍳6) FindRowsInMatrix ⊃3⍴⊂6/3 
0 0 0 0 0 0≡      (⊃6/¨⍳6) FindRowsInMatrix ,[-.5],7

For details see the PhraseBook/TestCasesGuidelines.

Test my code, both Examples and Test Cases.

See also: FindRowInMatrix

Mentor: KaiJaeger


CategoryPhrasesAll CategoryPhraseSelection

PhraseBook/FindRowsInMatrix (last edited 2011-12-26 19:20:29 by KaiJaeger)