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

FindRowInMatrix

Returns a Boolean with 1 for all the rows in matrix AM that match the vector AV:

      AM^.=AV

The length of the vector AV must match the number of columns in the matrix AM.

Thanks to scalar extension the expression also works with a scalar on the right side.

Examples

      ⎕FX ⍕2 1⍴'r←AM FindRowInMatrix AV' 'r←AM^.=AV'    ⍝ This will work in any APL dialect
      AM←⊃'Barak Obama' 'George Bush' 'Bill Clinton' 'Ronald Reagan' 'Gerald Ford' 'John Kennedy'
      AV←'Ronald Reagan'
      AM FindRowInMatrix AV
0 0 0 1 0 0
      (AM,[0]AM) FindRowInMatrix AV
0 0 0 1 0 0 0 0 0 1 0 0

How not to do it!

Transforming the matrix into a nested vector and then using ≡¨ is more expensive and therefore slower:

     (⊂[1]#.AM)≡¨⊂#.AV

In Dyalog it is about 24% slower than the phrase .

Compatibility

Checked with: APLX, NARS2000, Dyalog

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←AM FindRowInMatrix AV' 'r←AM^.=AV'    ⍝ This will work in any APL dialect
⍝ ---- Start Test cases (do not delete this!)
0 0 0 1 ≡ (⊃'Barak Obama' 'George Bush' 'Bill Clinton' 'Ronald Reagan') FindRowInMatrix 'Ronald Reagan'
⍬≡(0 13⍴' ') FindRowInMatrix 'Ronald Reagan'
0 0 0 1 0 0≡(⊃6/¨⍳6) FindRowInMatrix 3
0 0 0 0 0 0≡(⊃6/¨⍳6) FindRowInMatrix 7

For details see the PhraseBook/TestCasesGuidelines.

Test my code, both Examples and Test Cases.

See also: FindRowsInMatrix

Mentor: KaiJaeger


CategoryPhrasesAll CategoryPhraseSelection

PhraseBook/FindRowInMatrix (last edited 2011-12-26 19:20:04 by KaiJaeger)