Table Of Contents
Table Of Contents

CSRNDArray.__setitem__

CSRNDArray.__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 CSRNDArray or numpy.ndarray) – The value to set.

Examples

>>> src = mx.nd.sparse.zeros('csr', (3,3))
>>> src.asnumpy()
array([[ 0.,  0.,  0.],
       [ 0.,  0.,  0.],
       [ 0.,  0.,  0.]], dtype=float32)
>>> # assign CSRNDArray with same storage type
>>> x = mx.nd.ones((3,3)).tostype('csr')
>>> x[:] = src
>>> x.asnumpy()
array([[ 1.,  1.,  1.],
       [ 1.,  1.,  1.],
       [ 1.,  1.,  1.]], dtype=float32)
>>> # assign NDArray to CSRNDArray
>>> x[:] = mx.nd.ones((3,3)) * 2
>>> x.asnumpy()
array([[ 2.,  2.,  2.],
       [ 2.,  2.,  2.],
       [ 2.,  2.,  2.]], dtype=float32)