'x.__setitem__(i, y) <=> x[i]=y
Set self[key] to value.
Parameters
key : int, slice or tuple
The indexing key.
value : scalar, NDArray or numpy.ndarray
The value to set.
Examples
>>> x = mx.nd.zeros((2,3))
>>> x[:] = 1
>>> x.asnumpy()
array([[ 1.,  1.,  1.],
[ 1.,  1.,  1.]], dtype=float32)
>>> x.asnumpy()
array([[ 1.,  1.,  1.],
[ 1.,  1.,  1.]], dtype=float32)
>>> x[:,1:2] = 2
>>> x.asnumpy()
array([[ 1.,  2.,  1.],
[ 1.,  2.,  1.]], dtype=float32)
>>> x[1:2,1:] = 3
>>> x.asnumpy()
array([[ 1.,  2.,  1.],
[ 1.,  3.,  3.]], dtype=float32)
>>> x[1:,0:2] = mx.nd.zeros((1,2))
>>> x.asnumpy()
array([[ 1.,  2.,  1.],
[ 0.,  0.,  3.]], dtype=float32)
>>> x[1,2] = 4
>>> x.asnumpy()
array([[ 1.,  2.,  1.],
[ 0.,  0.,  4.]], dtype=float32)'

def __setitem__(self, key, value):

    if (not self.writable):
        raise ValueError('Cannot    assign    to    readonly    NDArray')
    if isinstance(key, integer_types):
        sliced_arr = self._at(key)
        sliced_arr[:] = value
        return
    elif isinstance(key, py_slice):
        if (key.step is not None):
            raise ValueError('NDArray    only    supports    slicing    with    step    size    1')
        if ((key.start is not None) or (key.stop is not None)):
            sliced_arr = self._slice(key.start, key.stop)
            sliced_arr[:] = value
            return
        if isinstance(value, NDArray):
            if (value.handle is not self.handle):
                value.copyto(self)
        elif isinstance(value, numeric_types):
            _internal._set_value(float(value), out=self)
        elif isinstance(value, (np.ndarray, np.generic)):
            self._sync_copyfrom(value)
        else:
            raise TypeError(('NDArray    does    not    support    assignment    with    %s    of    type    %s' % (str(value), str(type(value)))))
    elif isinstance(key, tuple):
        my_shape = self.shape
        assert (len(key) <= len(my_shape)), ('Indexing    dimensions    exceed    array    dimensions,    %d    vs    %d' % (len(key), len(my_shape)))
        begin = [0 for _ in my_shape]
        end = [x for x in my_shape]
        expand = []
        for (i, slice_i) in enumerate(key):
            if isinstance(slice_i, integer_types):
                assert (slice_i < my_shape[i])
                begin[i] = slice_i
                end[i] = (slice_i + 1)
                expand.append(i)
            elif isinstance(slice_i, py_slice):
                assert (slice_i.step is None), 'NDArray    only    supports    slicing    with    step    size    1.'
                begin[i] = (slice_i.start or 0)
                end[i] = (slice_i.stop or my_shape[i])
                assert (begin[i] < end[i])
                assert (end[i] <= my_shape[i])
            else:
                raise ValueError(('NDArray    does    not    support    slicing    with    key    %s    of    type    %s.' % (str(slice_i), str(type(slice_i)))))
        if isinstance(value, NDArray):
            value = value.as_in_context(self.context)
            self._slice_assign(value, begin, end, expand)
        elif isinstance(value, numeric_types):
            _internal._crop_assign_scalar(self, out=self, begin=begin, end=end, scalar=value)
        elif isinstance(value, (np.ndarray, np.generic)):
            value = array(value, ctx=self.context, dtype=self.dtype)
            self._slice_assign(value, begin, end, expand)
        else:
            raise TypeError(('NDArray    does    not    support    assignment    with    %s    of    type    %s' % (str(value), str(type(value)))))
    else:
        raise ValueError(('NDArray    does    not    support    slicing    with    key    %s    of    type    %s.' % (str(key), str(type(key)))))
