Matrix transposition: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|Haskell}}: Added a variant expressed in terms of Data.Matrix) |
||
Line 2,283: | Line 2,283: | ||
[[1,4,7],[2,5,8],[3,6,9]] |
[[1,4,7],[2,5,8],[3,6,9]] |
||
</pre> |
</pre> |
||
or, in terms of Data.Matrix: |
|||
<syntaxhighlight lang="haskell">import Data.Matrix |
|||
main :: IO () |
|||
main = |
|||
let matrix = fromList 3 4 [1 ..] |
|||
in print matrix >> print (transpose matrix)</syntaxhighlight> |
|||
{{Out}} |
|||
<pre>┌ ┐ |
|||
│ 1 2 3 4 │ |
|||
│ 5 6 7 8 │ |
|||
│ 9 10 11 12 │ |
|||
└ ┘ |
|||
┌ ┐ |
|||
│ 1 5 9 │ |
|||
│ 2 6 10 │ |
|||
│ 3 7 11 │ |
|||
│ 4 8 12 │ |
|||
└ ┘</pre> |
|||
===With Numeric.LinearAlgebra=== |
===With Numeric.LinearAlgebra=== |