Naming Conventions |
|||||
|
Scalar |
Vector |
Matrix |
Any |
Non- |
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 |
ES |
EV |
EM |
EA |
EN |
enclosed |
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 scalar∨vector |
|||||
B3, I4 &c. to specify higher ranks. |
|||||
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 my code, both Examples and Test Cases.
See also: FindRowsInMatrix
Mentor: KaiJaeger
APL Wiki