Search code examples
scala-breeze

Most efficient way to remove a range of rows from a DenseMatrix?


I want to remove rows M+1 through N in a DenseMatrix (DM_a below), to produce another DenseMatrix (DM_b). Something like this:

                               K
DM_a =   0 +-------------------+
           |                   |
           |                   |
           |                   |
         M |                   |
           |                   |
           |                   |
           |                   |
         N +-------------------+



                               K
DM_b =   0 +-------------------+
           |                   |
           |                   |
           |                   |
         M +-------------------+

Is it best (most efficient) to do this with slicing like this: val DM_b = DM_a(0 to M, ::) or should I map padRight to each column of DM_a?


Solution

  • matrix slice:

      DM_a(0 until M, ::)