Essays/Transpose
< Essays
Jump to navigation
Jump to search
The verb |: (transpose) can be modelled as follows:
mask =: = /: ~. rho =: <./@# ind =: (#:i.)@:rho +/ .* #.~ transposeAPL=: (mask@[ ind $@]) { ,@] rank =: #@$ pfill =: (i.@[ -. |) , | en =: - #@; ci =: (/:@pfill ;) { i.@en , en + (#&> # i.@#)@] tsp2 =: (rank@] ci [) transposeAPL ] transpose =: (i.@-@rank tsp2 ]) : tsp2
tranposeAPL is dyadic transpose in APL. transpose models the verb |: . For example:
y=: 3 5 7 11 13 17 ?@$ 1e6 (|: -: transpose) y 1 (?~ #$y) (|: -: transpose) y 1 (4 0;1 3 2) (|: -: transpose) y 1
transposeAPL is a translation into J of a model in Dictionary APL that appeared in Section 3.1 of R.K.W. Hui, Some Uses of { and }, APL87, 1987-05-10.
⍺⍉⍵: ((>{⍳¨>(⍴⍵)⌊.+¯×~k)+.×(⍴⍵)⊥k){,⍵ ⊣ k←⍺∘.=⍳1+⌈/⍺
Contributed by Roger Hui.