用Java转置矩阵
矩阵的转置是矩阵在其对角线上翻转,即矩阵的行索引和列索引被切换。一个例子如下:
Matrix = 1 2 3 4 5 6 7 8 9 Transpose = 1 4 7 2 5 8 3 6 9
演示该程序的程序如下。
示例
public class Example {
public static void main(String args[]) {
int i, j;
int row = 3;
int col = 2;
int arr[][] = {{2, 5}, {1, 8}, {6, 9} };
System.out.println("The original matrix is: ");
for(i = 0; i < row; i++) {
for(j = 0; j < col; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.print("\n");
}
System.out.println("The matrix transpose is: ");
for(i = 0; i < col; i++) {
for(j = 0; j < row; j++) {
System.out.print(arr[j][i] + " ");
}
System.out.print("\n");
}
}
}输出结果
The original matrix is: 2 5 1 8 6 9 The matrix transpose is: 2 1 6 5 8 9
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿