You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2017/10/22 06:19:25 UTC
[GitHub] eric-haibin-lin commented on a change in pull request #8362: Add asscipy feature
eric-haibin-lin commented on a change in pull request #8362: Add asscipy feature
URL: https://github.com/apache/incubator-mxnet/pull/8362#discussion_r146122727
##########
File path: python/mxnet/ndarray/sparse.py
##########
@@ -492,6 +492,24 @@ def copyto(self, other):
else:
raise TypeError('copyto does not support type ' + str(type(other)))
+ def asscipy(self):
+ """Returns a ``scipy.sparse.csr.csr_matrix`` object with value copied from this array
+
+ Examples
+ --------
+ >>> x = mx.nd.sparse.zeros('csr', (2,3))
+ >>> y = x.asscipy()
+ >>> type(y)
+ <type 'scipy.sparse.csr.csr_matrix'>
+ >>> y
+ <2x3 sparse matrix of type '<type 'numpy.float32'>'
+ with 0 stored elements in Compressed Sparse Row format>
+ """
+ data = self.data.asnumpy()
+ indices = self.indices.asnumpy()
+ indptr = self.indptr.asnumpy()
+ return spsp.csr_matrix((data, indices, indptr), shape=self.shape)
Review comment:
Please also pass along dtype information and create a test for it
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services