val result = 0 until matrix.rows map { rowIndex => val colIndex = colIndices(rowIndex) matrix(rowIndex, colIndex) } |
Hello. I'm looking for a more efficient way of getting a DenseVector from a DenseMatrix where column index is different for every row. My current solution (colIndices is a DenseVector):
val result = 0 until matrix.rows map { rowIndex => val colIndex = colIndices(rowIndex) matrix(rowIndex, colIndex) }
--
You received this message because you are subscribed to the Google Groups "Scala Breeze" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-breeze+unsubscribe@googlegroups.com.
To post to this group, send email to scala-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-breeze/25125c6b-6ad2-48a6-b50a-a6af25d1963f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
same basic answers as the other one for efficiency.If you just want economical, you can probably just do: DenseVector.tabulate(matrix.rows) { rowIndex => ... }Or you can use a slice vector, which isn't a dense vector, but can be made into one.matrix(colIndices.toIndexedSeq.zipWithIndex.map(_.swap)).toDenseVector
On Mon, Mar 26, 2018 at 2:47 AM, <nejc....@gmail.com> wrote:
Hello. I'm looking for a more efficient way of getting a DenseVector from a DenseMatrix where column index is different for every row. My current solution (colIndices is a DenseVector):
val result = 0 until matrix.rows map { rowIndex => val colIndex = colIndices(rowIndex) matrix(rowIndex, colIndex) }
--
You received this message because you are subscribed to the Google Groups "Scala Breeze" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-breeze...@googlegroups.com.