mxnet.ndarray.sparse.row_sparse_array¶
-
mxnet.ndarray.sparse.
row_sparse_array
(arg1, shape=None, ctx=None, dtype=None)[source]¶ Creates a RowSparseNDArray, a multidimensional row sparse array with a set of tensor slices at given indices.
The RowSparseNDArray can be instantiated in several ways:
- row_sparse_array(D):
to construct a RowSparseNDArray with a dense ndarray
D
- D (array_like) - An object exposing the array interface, an object whose __array__ method returns an array, or any (nested) sequence. - ctx (Context, optional) - Device context (default is the current default context). - dtype (str or numpy.dtype, optional) - The data type of the output array. The default dtype isD.dtype
ifD
is an NDArray or numpy.ndarray, float32 otherwise.
- row_sparse_array(S)
to construct a RowSparseNDArray with a sparse ndarray
S
- S (RowSparseNDArray) - A sparse ndarray. - ctx (Context, optional) - Device context (default is the current default context). - dtype (str or numpy.dtype, optional) - The data type of the output array. The default dtype isS.dtype
.
- row_sparse_array((D0, D1 .. Dn))
to construct an empty RowSparseNDArray with shape
(D0, D1, ... Dn)
- D0, D1 .. Dn (int) - The shape of the ndarray - ctx (Context, optional) - Device context (default is the current default context). - dtype (str or numpy.dtype, optional) - The data type of the output array. The default dtype is float32.
- row_sparse_array((data, indices))
to construct a RowSparseNDArray based on the definition of row sparse format using two separate arrays, where the indices stores the indices of the row slices with non-zeros, while the values are stored in data. The corresponding NDArray
dense
represented by RowSparseNDArrayrsp
hasdense[rsp.indices[i], :, :, :, ...] = rsp.data[i, :, :, :, ...]
The row indices for are expected to be sorted in ascending order. - data (array_like) - An object exposing the array interface, which holds all the non-zero row slices of the array. - indices (array_like) - An object exposing the array interface, which stores the row index for each row slice with non-zero elements. - shape (tuple of int, optional) - The shape of the array. The default shape is inferred from the indices and indptr arrays. - ctx (Context, optional) - Device context (default is the current default context). - dtype (str or numpy.dtype, optional) - The data type of the output array. The default dtype is float32.
- Parameters
arg1 (NDArray, numpy.ndarray, RowSparseNDArray, tuple of int or tuple of array_like) – The argument to help instantiate the row sparse ndarray. See above for further details.
shape (tuple of int, optional) – The shape of the row sparse ndarray. (Default value = None)
ctx (Context, optional) – Device context (default is the current default context).
dtype (str or numpy.dtype, optional) – The data type of the output array. (Default value = None)
- Returns
An RowSparseNDArray with the row_sparse storage representation.
- Return type
Examples
>>> a = mx.nd.sparse.row_sparse_array(([[1, 2], [3, 4]], [1, 4]), shape=(6, 2)) >>> a.asnumpy() array([[ 0., 0.], [ 1., 2.], [ 0., 0.], [ 0., 0.], [ 3., 4.], [ 0., 0.]], dtype=float32)
See also
RowSparseNDArray()
MXNet NDArray in row sparse format.