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. |
|||||
FindFirstChange
Returns a vector of Booleans indicating the rows in a matrix were a change takes place. Note that the matrix needs to be sorted in order to work.
¯1↓1,∨/AM≠1⊖AM
Examples
⎕FX ⍕2 1⍴'R←FindFirstChange AM' 'R←¯1↓1,∨/AM≠1⊖AM'
⎕←AM←⊃2 4 1 3/'Adam' 'Ben' 'Cesar' 'Emil'
Adam
Adam
Ben
Ben
Ben
Ben
Cesar
Emil
Emil
Emil
FindFirstChange AM
1 0 1 0 0 0 1 1 0 0
⎕←AM←13 2⍴1 1 1 1 1 2 1 2 1 2 1 3 2 1 2 1 2 2 2 3 2 4 3 1 3 1
1 1
1 1
1 2
1 2
1 2
1 3
2 1
2 1
2 2
2 3
2 4
3 1
3 1
FindFirstChange AM
1 0 1 0 0 1 1 0 1 1 1 1 0
How not to do it!
(AV⍳AV)=⍳⍴AV←⊂[1+⎕IO]AM
In Dyalog this is about 2.5 times slower than the phrase.
However, this expression works no matter whether the matrix is sorted or not.
Conforming Variants
...
Specialities
....
Compatibility
Checked with: APL2, APLX, Dyalog, NARS2000
Test Cases
Show test cases
Test my code, both Examples and Test Cases.
See also: Accumulate
Mentor: KaiJaeger
Tags: <FindChanges> <DetectChanges>
APL Wiki