Scala 线性代数库 Breeze(二):矩阵操作

矩阵加法

val m1 = DenseMatrix((1, 2, 3), (4, 5, 6))  
val m2 = DenseMatrix((6, 5, 4), (3, 2, 1))  
val result = m1 + m2  

matrix_add_matrix

标量乘法

val m1 = DenseMatrix((1, 2, 3), (4, 5, 6))  
val result = m1 * 2  

matrix_mult_num

矩阵向量乘法

val m = DenseMatrix((1, 2, 3), (4, 5, 6))  
val v = DenseVector(1, 2, 3)  
val result = m * v  

matrix_mult_vector

矩阵乘法

val m1 = DenseMatrix((1, 2, 3), (4, 5, 6))  
val m2 = DenseMatrix((1, 2), (3, 4), (5,6))  
val result = m1 * m2  

matrix_multi_matrix

矩阵转置

val m1 = DenseMatrix((1, 2, 3), (4, 5, 6))  
val result = m1.t  

matrix_transpose

非奇异方阵逆元

val m1 = DenseMatrix((1, 2, 3), (0, 1, 4), (0, 0, 1))  
val result = inv(m1)  

matrix_inverse