Save DenseMatrix to text file

562 views
Skip to first unread message

Alex Minnaar

unread,
Jul 11, 2014, 3:39:13 PM7/11/14
to scala-...@googlegroups.com
Hi.  Could someone suggest the best way to save a DenseMatrix to a text file.  I have tried

val writer = new PrintWriter(new File("test.txt" ))
writer.write(new DenseMatrix[Double](K, vocabSize, Gamma(100.0, 1.0 / 100.0).sample(K * vocabSize).toArray).toString)
writer.close()


But it seems to write a truncated version of the matrix (i.e. one with "...")

So if someone could shed some light on this for me, that would be great.

Thanks,

Alex

David Hall

unread,
Jul 11, 2014, 3:51:45 PM7/11/14
to scala-...@googlegroups.com
val dm = // ...
breeze.linalg.csvwrite(new File("text.txt"), dm, separator = ' ')

should do it.

Also, DenseMatrix.rand(K, vocabSize, Gamma(100.0, 1.0 / 100.0)) ought to work for making the matrix




--
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/8fac657a-d058-4ef5-9130-9c650101ff04%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Minnaar

unread,
Jul 11, 2014, 3:57:54 PM7/11/14
to scala-...@googlegroups.com, dl...@cs.berkeley.edu
Thanks.  Worked perfectly.
Reply all
Reply to author
Forward
0 new messages