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

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
 ⎕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'R←FindFirstChange AM' 'R←¯1↓1,∨/AM≠1⊖AM'
⍝ ---- Start Test cases (do not delete this!)
⍬≡FindFirstChange 0 10⍴''
(,1)≡FindFirstChange 1 10⍴''
⍬≡FindFirstChange 0 10⍴0
(,1)≡FindFirstChange 1 10⍴0
1 0 0≡FindFirstChange 3 2⍴'AA'
1 0 0≡FindFirstChange 3 2⍴1 2
1 0 1≡FindFirstChange 3 2⍴'AAAABB'
1 0 1≡FindFirstChange 3 2⍴1 2 1 2 1 3

For details see the PhraseBook/TestCasesGuidelines.

Test my code, both Examples and Test Cases.

See also: Accumulate

Mentor: KaiJaeger

Tags: <FindChanges> <DetectChanges>


CategoryPhrasesAll - CategoryPhraseBooleans

phrasebook/findfirstchange (last edited 2011-12-26 10:36:51 by KaiJaeger)