Matrix transposition: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 279: | Line 279: | ||
import java.util.Arrays; |
import java.util.Arrays; |
||
public class Transpose{ |
public class Transpose{ |
||
public static void main(String[] args){ |
|||
double[][] m = {{1, 1, 1, 1}, |
|||
{2, 4, 8, 16}, |
|||
{3, 9, 27, 81}, |
|||
{4, 16, 64, 256}, |
|||
{5, 25, 125, 625}}; |
|||
double[][] ans = new double[m[0].length][m.length]; |
|||
for(int rows = 0; rows < m.length; rows++){ |
|||
for(int cols = 0; cols < m[0].length; cols++){ |
|||
ans[cols][rows] = m[rows][cols]; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
for(double[] i:ans){//2D arrays are arrays of arrays |
|||
System.out.println(Arrays.toString(i)); |
|||
} |
|||
} |
|||
} |
|||
} |
} |
||
Line 322: | Line 322: | ||
1.00000 8.00000 27.00000 64.00000 125.00000 |
1.00000 8.00000 27.00000 64.00000 125.00000 |
||
1.00000 16.00000 81.00000 256.00000 625.00000 |
1.00000 16.00000 81.00000 256.00000 625.00000 |
||
=={{header|Pop11}}== |
|||
<pre> |
|||
define transpose(m) -> res; |
|||
lvars bl = boundslist(m); |
|||
if length(bl) /= 4 then |
|||
throw([need_2d_array ^a]) |
|||
endif; |
|||
lvars i, i0 = bl(1), i1 = bl(2); |
|||
lvars j, j0 = bl(3), j1 = bl(4); |
|||
newarray([^j0 ^j1 ^i0 ^i1], 0) -> res; |
|||
for i from i0 to i1 do |
|||
for j from j0 to j1 do |
|||
m(i, j) -> res(j, i); |
|||
endfor; |
|||
endfor; |
|||
enddefine; |
|||
</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
||
Line 344: | Line 363: | ||
=={{header|TI-83 BASIC}}== |
=={{header|TI-83 BASIC}}== |
||
Assuming the original matrix is in <tt>[A]</tt>, place its transpose in <tt>[B]</tt>: |
Assuming the original matrix is in <tt>[A]</tt>, place its transpose in <tt>[B]</tt>: |
||
[A]<sup>T</sup> |
[A]<sup>T</sup>->[B] |
||
The <sup>T</sup> operator can be found in the matrix math menu. |
The <sup>T</sup> operator can be found in the matrix math menu. |