Anonymous user
Matrix transposition: Difference between revisions
added common lisp and ruby
(→{{header|Python}}: Colourized) |
(added common lisp and ruby) |
||
Line 112:
PRINT
NEXT rows
=={{header|Common Lisp}}==
<lisp>(defun transpose (m)
(apply #'map #'list m))</lisp>
=={{header|D}}==
<
import std.stdio ;
import std.string ;
Line 153 ⟶ 157:
n = m.transpose() ;
writefln(" n (m's transpose) = ", n.toString()) ;
}</
Line 243 ⟶ 247:
=={{header|Java}}==
}</java>
=={{header|Mathematica}}==
Line 353 ⟶ 357:
=={{header|Perl}}==
{{libheader|Math::Matrix}}
Output:
Line 391 ⟶ 395:
=={{header|Python}}==
<python>m=((1,
(5, 25,125, 625));▼
▲ print(zip(*m))</python>
Output:
[(1, 2, 3, 4, 5),
Line 403 ⟶ 406:
(1, 8, 27, 64, 125),
(1, 16, 81, 256, 625)]
=={{header|Ruby}}==
<ruby>m=[[1, 1, 1, 1],
[2, 4, 8, 16],
[3, 9, 27, 81],
[4, 16, 64, 256],
puts m.transpose</ruby>
Output:
[[1, 2, 3, 4, 5], [1, 4, 9, 16, 25], [1, 8, 27, 64, 125], [1, 16, 81, 256, 625]]
=={{header|Scheme}}==
=={{header|TI-83 BASIC}}==
|