DenseMatrix array masking

14 views
Skip to first unread message

Rahul Palamuttam

unread,
Jul 21, 2015, 2:18:29 PM7/21/15
to scalanlp...@googlegroups.com
Hi I wanted to create masked arrays and wanted to know how to do this using the DenseMatrix syntax.

I was looking for something like DenseMatrix <= num. Which will give me another dense matrix of elements less than num, or 0 otherwise.

David Hall

unread,
Jul 21, 2015, 3:46:22 PM7/21/15
to scalanlp...@googlegroups.com
it is not fast, but:

where(dm :<= num, dm, DenseMatrix.zeros[Double](dm.rows, dm.cols))

or 

dm.map { v => if (v <= num) v else 0.0 }

or 

dm :* I(dm :<= 5)
Reply all
Reply to author
Forward
0 new messages