Matrix transposition: Difference between revisions

m
No edit summary
Line 551:
for {set i 0} {$i < $rows} {incr i} {
for {set j 0} {$j < $cols} {incr j} {
puts -nonewline [format "%*s " [lindex $max $j] [lindex $m $i $j]]
}
puts ""
Line 558:
proc widest {m} {
lassign [size $m] rows cols
set max [lrepeat $cols 0]
for {set i 0} {$i < $rows} {incr i} {
for {set j 0} {$j < $cols} {incr j} {
setlset max $j [max [lindex $max $j] [string length [lindex $m $i $j]]]
}
}
Line 571:
print_matrix [transpose $m]</lang>
outputs
<pre> 1 1 1 1
2 4 8 16
3 9 27 81
4 16 64 256
5 25 125 625
1 2 3 4 5
1 4 9 16 25
1 8 27 64 125
1 16 81 256 625</pre>
Using the struct::matrix package from [http://tcllib.sf.net tcllib]
<lang tcl>package require struct::matrix
Anonymous user