[ 
https://issues.apache.org/jira/browse/SPARK-10127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14704200#comment-14704200
 ] 

Apache Spark commented on SPARK-10127:
--------------------------------------

User 'taishi-oss' has created a pull request for this issue:
https://github.com/apache/spark/pull/8327

> Add numpy-like indexing interface for DenceMatrix
> -------------------------------------------------
>
>                 Key: SPARK-10127
>                 URL: https://issues.apache.org/jira/browse/SPARK-10127
>             Project: Spark
>          Issue Type: New Feature
>          Components: MLlib
>            Reporter: Hiroshi Takahashi
>
> Currently, we don't have good interface to access sub-matrix.
> It's inconvenience to prototype manipulate matrix via spark-shell for the 
> reason.
> My suggestion is to add operator "!" as operator of accessing sub-matrix 
> instead of numpy's ().
> for example:
> {code}
> scala> import org.apache.spark.mllib.linalg.DenseMatrix
> import org.apache.spark.mllib.linalg.DenseMatrix
> scala> val dm = new DenseMatrix(3, 3, Array(1.0, 4.0, 7.0, 2.0, 5.0, 8.0, 
> 3.0, 6.0, 9.0))
> dm: org.apache.spark.mllib.linalg.DenseMatrix = 
> 1.0  2.0  3.0  
> 4.0  5.0  6.0  
> 7.0  8.0  9.0  
> // get row
> scala> dm!(1)
> res0: org.apache.spark.mllib.linalg.DenseMatrix = 4.0  5.0  6.0  
> // get (i, j)
> scala> dm!(1, 2)
> res1: Double = 6.0
> // get colmun
> scala> dm!((), 1)
> res2: org.apache.spark.mllib.linalg.DenseMatrix = 
> 2.0  
> 5.0  
> 8.0  
> // get columns between i and j-1
> scala> dm!((), (1, 3))
> res3: org.apache.spark.mllib.linalg.DenseMatrix = 
> 2.0  3.0  
> 5.0  6.0  
> 8.0  9.0  
> // get rows between i and j-1
> scala> dm!((1, 3))
> res4: org.apache.spark.mllib.linalg.DenseMatrix = 
> 4.0  5.0  6.0  
> 7.0  8.0  9.0  
> // get sub-matrix between (i1, j1-1) and (i2, j2-1)
> scala> dm!((1, 3), (1, 3))
> res5: org.apache.spark.mllib.linalg.DenseMatrix = 
> 5.0  6.0  
> 8.0  9.0  
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org
For additional commands, e-mail: issues-h...@spark.apache.org

Reply via email to