Matrix transposition: Difference between revisions

m (→‎{{header|Phix}}: added syntax colouring the hard way, minor improvements: calculate lengths just the once)
Line 1,917:
transpArray a = ixmap (swap l, swap u) swap a where
(l,u) = bounds a</lang>
 
Using ''zipWith'' assuming a matrix is a list of row lists:
<lang haskell>
tpose [ms] = [[m] | m <- ms]
tpose (ms:mss) = zipWith (:) ms (tpose mss)
</lang>
{{out}}
<pre>
tpose [[1,2,3],[4,5,6],[7,8,9]]
[[1,4,7],[2,5,8],[3,6,9]]
</pre>
 
===With Numeric.LinearAlgebra===
Anonymous user