RowSparseNDArray¶
-
class
mxnet.ndarray.sparse.
RowSparseNDArray
(handle, writable=True)[source]¶ A sparse representation of a set of NDArray row slices at given indices.
A RowSparseNDArray represents a multidimensional NDArray using two separate arrays: data and indices. The number of dimensions has to be at least 2.
data: an NDArray of any dtype with shape [D0, D1, …, Dn].
indices: a 1-D int64 NDArray with shape [D0] with values sorted in ascending order.
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, :, :, :, ...]
>>> dense.asnumpy() array([[ 1., 2., 3.], [ 0., 0., 0.], [ 4., 0., 5.], [ 0., 0., 0.], [ 0., 0., 0.]], dtype=float32) >>> rsp = dense.tostype('row_sparse') >>> rsp.indices.asnumpy() array([0, 2], dtype=int64) >>> rsp.data.asnumpy() array([[ 1., 2., 3.], [ 4., 0., 5.]], dtype=float32)
A RowSparseNDArray is typically used to represent non-zero row slices of a large NDArray of shape [LARGE0, D1, .. , Dn] where LARGE0 >> D0 and most row slices are zeros.
RowSparseNDArray is used principally in the definition of gradients for operations that have sparse gradients (e.g. sparse dot and sparse embedding).
See also
row_sparse_array
Several ways to construct a RowSparseNDArray
Array attributes¶
Device context of the array. |
|
A deep copy NDArray of the data array of the RowSparseNDArray. |
|
Data-type of the array’s elements. |
|
A deep copy NDArray of the indices array of the RowSparseNDArray. |
|
Tuple of array dimensions. |
|
Storage-type of the array. |
Array conversion¶
Returns an array on the target device with the same value as this array. |
|
Return a dense |
|
Returns a scalar whose value is copied from this array. |
|
Return a copy of the array after casting to a specified type. |
|
Makes a copy of this |
|
Copies the value of this array to another array. |
|
Return a copy of the array with chosen storage type. |
Array inspection¶
Check whether the NDArray format is valid. |
Array creation¶
Convenience fluent method for |
Array rounding¶
Convenience fluent method for |
|
Convenience fluent method for |
|
Convenience fluent method for |
|
Convenience fluent method for |
|
Convenience fluent method for |
|
Convenience fluent method for |
Trigonometric functions¶
Convenience fluent method for |
|
Convenience fluent method for |
|
Convenience fluent method for |
|
Convenience fluent method for |
|
Convenience fluent method for |
|
Convenience fluent method for |
Hyperbolic functions¶
Convenience fluent method for |
|
Convenience fluent method for |
|
Convenience fluent method for |
|
Convenience fluent method for |
Exponents and logarithms¶
Convenience fluent method for |
|
Convenience fluent method for |
Indexing¶
x.__getitem__(i) <=> x[i] |
|
x.__setitem__(i, y) <=> x[i]=y |
|
Convenience fluent method for |
Lazy evaluation¶
Waits until all previous write operations on the current array are finished. |