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

InvertList

Convert an N-vector of M-vectors into an M-vector of N-vectors such that the Ith item of the result contains the Ith item of each item of the argument. This operation is called "zip" in functional languages, where it turns a pair of lists into a list of pairs. The standard coding is ⎕IO dependent which here assumes zero.

      ⊂[1]⍉⊃EV

Examples

      ⎕FX⍕2 1⍴'r←InvertList ev' 'r←⊂[1]⍉⊃ev'
      InvertList('zero' 'one' 'two')('three' 'four' 'five')
  zero  three    one  four    two  five 

      InvertList(0 1)(2 3)(4 5)
 0 2 4  1 3 5 

      InvertList'these' 'three' 'words'
 ttw  hho  err  sed  ees 

It's a self inverse when applied to a nested vector all of whose items have the same length.

      InvertList InvertList'these' 'three' 'words'
 these  three  words 

Specialities

Dyalog

This amazingly concise version, suggested by Pete Donnelly, depends on Dyalog's monadic as split which is equivalent to standard ⊂[0⊥⍳⍴⍴an]AN.

      ↓⍉↑ev  ⍝ ⎕ML≤1
      ↓⍉⊃ev  ⍝ ⎕ML>1

see http://www.dyalog.com/dfnsdws/tube_n_zip_cat.htm for a fuller description.

Compatibility

Checked with: APL2, APLX, Dyalog, NARS2000

Test Cases

Show test cases

 Test
 ⎕IO←0
⍝ ⎕ML←3      ⍝ Enable this line in Dyalog APL if appropriate
 ⎕FX⍕2 1⍴'r←InvertList ev' 'r←⊂[1]⍉⊃ev'
⍝ ---- Start Test cases (do not delete this!)
 (('zero' 'three')('one' 'four')('two' 'five'))≡InvertList('zero' 'one' 'two')('three' 'four' 'five')
 ((0 2 4)(1 3 5))≡InvertList(0 1)(2 3)(4 5)
 'ttw' 'hho' 'err' 'sed' 'ees'≡InvertList'these' 'three' 'words'
 'these' 'three' 'words'≡InvertList InvertList'these' 'three' 'words'

For details see the PhraseBook/TestCasesGuidelines.

Test my code, both Examples and Test Cases.

See also: ...

Mentor: PhilLast

Tags: <NestedTranspose> <Zip> <Swap>


CategoryPhrasesAll - CategoryPhraseStructure

PhraseBook/InvertList (last edited 2012-02-07 08:54:04 by KaiJaeger)