Table Of Contents
Table Of Contents


mxnet.ndarray.contrib.index_copy(old_tensor=None, index_vector=None, new_tensor=None, out=None, name=None, **kwargs)

Copies the elements of a new_tensor into the old_tensor.

This operator copies the elements by selecting the indices in the order given in index. The output will be a new tensor containing the rest elements of old tensor and the copied elements of new tensor. For example, if index[i] == j, then the i th row of new_tensor is copied to the j th row of output.

The index must be a vector and it must have the same size with the 0 th dimension of new_tensor. Also, the 0 th dimension of old_tensor must >= the 0 th dimension of new_tensor, or an error will be raised.


x = mx.nd.zeros((5,3))
t = mx.nd.array([[1,2,3],[4,5,6],[7,8,9]])
index = mx.nd.array([0,4,2])

mx.nd.contrib.index_copy(x, index, t)

[[1. 2. 3.]
 [0. 0. 0.]
 [7. 8. 9.]
 [0. 0. 0.]
 [4. 5. 6.]]
<NDArray 5x3 @cpu(0)>

Defined in src/operator/contrib/

  • old_tensor (NDArray) – Old tensor

  • index_vector (NDArray) – Index vector

  • new_tensor (NDArray) – New tensor to be copied

  • out (NDArray, optional) – The output NDArray to hold the result.


out – The output of this function.

Return type

NDArray or list of NDArrays