ndarray.__setitem__¶
-
ndarray.__setitem__(self, key, value)¶ Sets
self[key]tovalue.This functions supports advanced indexing as defined in the NumPy advanced indexing documentation, with the restriction that boolean array indexing is not supported.
Parameters: - key : int, slice, list, np.ndarray, mx.np.ndarray, or tuple of all previous types
The indexing key.
- value : scalar or array-like object that can be broadcast to the shape of self[key]
The value to set.
Examples
>>> x = np.zeros((2, 3)) >>> x[:] = 1 >>> x array([[ 1., 1., 1.], [ 1., 1., 1.]]) >>> x[:, 1:2] = 2 >>> x array([[ 1., 2., 1.], [ 1., 2., 1.]]) >>> x[1:2, 1:] = 3 >>> x array([[ 1., 2., 1.], [ 1., 3., 3.]]) >>> x[1:, 0:2] = np.zeros((1, 2)) >>> x array([[ 1., 2., 1.], [ 0., 0., 3.]]) >>> x[1, 2] = 4 >>> x array([[ 1., 2., 1.], [ 0., 0., 4.]]) >>> x[[0], [1, 2]] = 5 >>> x array([[ 1., 5., 5.], [ 0., 0., 4.]]) >>> x[::-1, 0:2:2] = [6] >>> x array([[ 6., 5., 5.], [ 6., 0., 4.]])