Getting raw vector data

20 views
Skip to first unread message

Daniel Korzekwa

unread,
May 26, 2015, 7:25:35 AM5/26/15
to scala-...@googlegroups.com
Consider the following code:

  val d = new DenseMatrix(2, 2, Array(1.0, 2, 3, 4))
  
  diag(d).data //(1,2,3,4)
  diag(d).toArray //(1,4)

The data() method returns the raw data before applying diag() function, whereas toArray() returns the result of a diag() operation.

How data() and toArray() methods differ?, and why the resulting vector of diag() operation contains the original vector elements?

David Hall

unread,
May 26, 2015, 1:19:25 PM5/26/15
to scala-...@googlegroups.com
Many operations on DenseVectors and DenseMatrices return views of the original array. (For example, diag, slices, fliplr, flipud). `.data` always returns the original array. .toArray creates a copy containing just the elements of the vector. .copy.data also works.

-- David

--
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.
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/5e0292ea-25a8-4723-aa68-4d3231f53f5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages