0

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?

Chuck Wooters
  • 1,224
  • 8
  • 7

1 Answers1

1

matrix slice:

  DM_a(0 until M, ::)
dlwh
  • 2,257
  • 11
  • 23
  • Awesome, thanks! So, what's the difference between the `to` and `until` versions of the slice? – Chuck Wooters May 04 '16 at 21:18
  • to is inclusive, until is exclusive (note that the parameters to a slice are just scala.Range objects) – dlwh May 04 '16 at 21:33
  • Ah, I see, thanks. So then, wouldn't I want `0 to M` since I wanted to remove the rows beginning with row `M+1`? Or alternatively, I guess I'd need `0 until M+1`, right? – Chuck Wooters May 04 '16 at 21:39