Script Library: 1238 scripts
 

transpose.r

REBOL [ Title: "Transpose" Date: 3-Jul-2002 Name: 'Transpose Version: 1.0.0 File: %transpose.r Author: "Andrew Martin" Purpose: "Transposes a Matrix's rows and columns." eMail: %Al--Bri--xtra--co--nz Web: http://valley.150m.com Acknowledgements: [ "Joel Neely" "Gerald Goertzel" "Larry" ] Example: [ transpose [[1 2 3 4 5] ["a" "b" "c" "d" "e"]] transpose [[1 2 3] [14 15 16] [27 28 29]] ] library: [ level: 'intermediate platform: 'all type: 'tool domain: 'math tested-under: none support: none license: none see-also: none ] ] Transpose: function [ "Transposes a Matrix's rows and columns." [catch] Matrix [block!] "The Matrix." ][ Rows Columns Transposed ][ throw-on-error [ Rows: length? Matrix Columns: length? Matrix/1 Transposed: array reduce [Columns Rows] repeat Row Rows [ repeat Column Columns [ poke pick Transposed Column Row pick pick Matrix Row Column ] ] Transposed ] ]
halt ;; to terminate script if DO'ne from webpage
Notes
  • email address(es) have been munged to protect them from spam harvesters. If you are a Library member, you can log on and view this script without the munging.
  • (Al:Bri:xtra:co:nz)