You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by zhangjp <59...@qq.com> on 2016/01/22 13:56:36 UTC

回复: retrieve cell value from a rowMatrix.

Hi  Srini,
   If you want to get value like the following example using scala, some other language also like this 
     " mat.rows.collect().apply(i)
      val cov = mat.computeCovariance()
      cov.apply(i, j)
     "
   mat is RowMatrix type and  the cov is Matrix type.
  

 

 ------------------ 原始邮件 ------------------
  发件人: "Srivathsan Srinivas";<sr...@gmail.com>;
 发送时间: 2016年1月22日(星期五) 凌晨1:12
 收件人: "zhangjp"<59...@qq.com>; 
 抄送: "user"<us...@spark.apache.org>; 
 主题: Re: retrieve cell value from a rowMatrix.

 

 Hi Zhang,    I am new to Scala and Spark. I am not a Java guy (more of Python and R guy). Just began playing with matrices in MlLib and looks painful to do simple things. If you can show me a small example, it would help. Apply function is not available in RowMatrix. 
 

 For eg.,
 

 import org.apache.spark.mllib.linalg.distributed.RowMatrix
 

 /* retrive a cell value */
 def getValue(m: RowMatrix): Double = {
    <what should go in here>???
 }
 

 

 Likewise, I have trouble adding two RowMatrices
 

 /* add two RowMatrices */
 def addRowMatrices(a: RowMatrix, b: RowMatrix): RowMatrix = {
 

 }
 

 

 From what I have read on Stackoverflow and other places is that such simple things are not exposed in MlLib. But, they are heavily used in the underlying Breeze libraries. Hence, one should convert the rowMatrics to its Breeze equivalent, do the required operations and convert it back to rowMatrix. I am still learning how to do this kind of conversion back and forth. If you have small examples, it would be very helpful.
 

 

 Thanks!
 Srini.

 
 On Wed, Jan 20, 2016 at 10:08 PM, zhangjp <59...@qq.com> wrote:
   
  use apply(i,j) function.
 can u know how  to save matrix to a file using java language?

 

 ------------------ 原始邮件 ------------------
  发件人: "Srivathsan Srinivas";<sr...@gmail.com>;
 发送时间: 2016年1月21日(星期四) 上午9:04
 收件人: "user"<us...@spark.apache.org>; 
 
 主题: retrieve cell value from a rowMatrix.

   

 Hi,     Is there a way to retrieve the cell value of a rowMatrix? Like m(i,j)? The docs say that the indices are long. Maybe I am doing something wrong...but, there doesn't seem to be any such direct method.
 

 Any suggestions?
 

-- 
 Thanks,
Srini. 


 






 

-- 
 Thanks,
Srini.