简体   繁体   English

使用Scala在Breeze中使用矩阵行操作?

[英]Matrix Row manipulation in Breeze using Scala?

I've a DenseMatrix 我有一个DenseMatrix

1  2  3  0   0   0   0    0    0    
0  0  0  11  22  33  0    0    0    
0  0  0  0   0   0   111  222  333 

I want to remove the first row and then a last row with all 0 s 我想删除第一行,然后删除所有0秒的最后一行

0  0  0  11  22  33  0    0    0    
0  0  0  0   0   0   111  222  333 
0  0  0  0   0   0   0    0    0   

How do I achieve this in Breeze ? 我如何在微风中实现这一目标?

First, gather the rows you still want: 首先,收集您仍想要的行:

val subset = matrix(::, 2 to 3)

then add the zeroes: 然后添加零:

val newMatrix = DenseMatrix.horzcat(subset, DenseMatrix.zeros[Double](1,9))

I might have mixed up rows and columns in the last line. 我可能在最后一行混淆了行和列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM