Table Of Contents
Table Of Contents


mxnet.ndarray.sparse.array(source_array, ctx=None, dtype=None)[source]

Creates a sparse array from any object exposing the array interface.

  • source_array (RowSparseNDArray, CSRNDArray or scipy.sparse.csr.csr_matrix) – The source sparse array
  • ctx (Context, optional) – The default context is source_array.context if source_array is an NDArray. The current default context otherwise.
  • dtype (str or numpy.dtype, optional) – The data type of the output array. The default dtype is source_array.dtype if source_array is an NDArray, numpy.ndarray or scipy.sparse.csr.csr_matrix, float32 otherwise.

An array with the same contents as the source_array.

Return type:

RowSparseNDArray or CSRNDArray


>>> import scipy.sparse as spsp
>>> csr = spsp.csr_matrix((2, 100))
>>> mx.nd.sparse.array(csr)
<CSRNDArray 2x100 @cpu(0)>
>>> mx.nd.sparse.array(mx.nd.sparse.zeros('csr', (3, 2)))
<CSRNDArray 3x2 @cpu(0)>
>>> mx.nd.sparse.array(mx.nd.sparse.zeros('row_sparse', (3, 2)))
<RowSparseNDArray 3x2 @cpu(0)>