0、数据准备
var m1 = new DenseMatrix[Int](3,3,Array(1,2,3,4,5,6,7,8,9))
var m2 = new DenseMatrix[Int](3,3,Array(11,22,33,44,55,66,77,88,99))
1 4 7
2 5 8
3 6 9
11 44 77
22 55 88
33 66 99
1、调整矩阵形状
println(m1.reshape(1, 9))
1 2 3 4 5 6 7 8 9
2、矩阵转换为向量
println(m1.toDenseVector)
DenseVector(1, 2, 3, 4, 5, 6, 7, 8, 9)
3、复制下三角
println(lowerTriangular(m1))
1 0 0
2 5 0
3 6 9
4、复制上三角
println(upperTriangular(m1))
1 4 7
0 5 8
0 0 9
5、矩阵复制
m1.copy
6、取对角线元素
println(diag(m1))
DenseVector(1, 5, 9)
7、垂直连接矩阵
println(DenseMatrix.vertcat(m1, m2))
11 44 77
22 55 88
33 66 99
8、横向连接矩阵
println(DenseMatrix.horzcat(m1,m2))
1 4 7 11 44 77
2 5 8 22 55 88
3 6 9 33 66 99