Table Of Contents
Table Of Contents

RowSparseNDArray.__setitem__

RowSparseNDArray.__setitem__(key, value)[source]

x.__setitem__(i, y) <=> x[i]=y

Set self[key] to value. Only slice key [:] is supported.

Parameters:
  • key (slice) – The indexing key.
  • value (NDArray or numpy.ndarray) – The value to set.

Examples

>>> src = mx.nd.row_sparse([[1, 0, 2], [4, 5, 6]], [0, 2], (3,3))
>>> src.asnumpy()
array([[ 1.,  0.,  2.],
       [ 0.,  0.,  0.],
       [ 4.,  5.,  6.]], dtype=float32)
>>> # assign RowSparseNDArray with same storage type
>>> x = mx.nd.sparse.zeros('row_sparse', (3,3))
>>> x[:] = src
>>> x.asnumpy()
array([[ 1.,  0.,  2.],
       [ 0.,  0.,  0.],
       [ 4.,  5.,  6.]], dtype=float32)
>>> # assign NDArray to RowSparseNDArray
>>> x[:] = mx.nd.ones((3,3))
>>> x.asnumpy()
array([[ 1.,  1.,  1.],
       [ 1.,  1.,  1.],
       [ 1.,  1.,  1.]], dtype=float32)