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. |
|||||
RemoveDuplicateRows
Matrices can have duplicate rows which often have to be removed. The following phrase is universal for a simple matrix.
(∨⌿<\SM∧.=⍉SM)⌿SM
Examples
⎕FX⍕2 1⍴'r←RemoveDuplicateRows sm' 'r←(∨⌿<\sm∧.=⍉sm)⌿sm'
cm←7 4⍴'zero','one ','zero','one ','two ','one ','zero'
RemoveDuplicateRows cm
zero
one
two
RemoveDuplicateRows 0⌿cm ⍝ no rows
im←7 2⍴0 1,1 2,0 1,1 2,2 3,1 2,0 1
RemoveDuplicateRows 0/im ⍝ one empty row
RemoveDuplicateRows im
0 1
1 2
2 3
Specialities
Dyalog
This succinct and more general version (it works on matrices of any depth) which reads "reassemble into a matrix the unique elements of the nested vector formed from the rows of the original" is dependent upon the implementation of monadic ↑ as mix, ∪ as unique, ↓ as split and ⎕ML≤1.
↑∪↓am
APLX and Dyalog
This version uses the more standard (and verbose) ⊂[1] as enclose with axis with ⎕IO=0 and ⊃ as mix (requiring ⎕ML>1 in Dyalog).
⊃∪⊂[1]am
To remove the ⎕IO dependency substitute 0⊥⍳2 for the axis.
Compatibility
CheckedWith: APL2, Dyalog, APLX
Test Cases
Show test cases
Test my code, both Examples and Test Cases.
See also: RemoveDuplicates
Mentor: PhilLast
Tags: <DeleteDuplicates> <DupRowsOut> <SelectUniqueRows>
CategoryPhrasesAll - CategoryPhraseCharacterManipulation - CategoryPhraseSelection
APL Wiki