qml.math.scatter¶
- scatter(indices, array, new_dims, like=None)[source]¶
Scatters an array into a tensor of shape new_dims according to indices.
This operation is similar to scatter_element_add, except that the tensor is zero-initialized. Calling scatter(indices, array, new_dims) is identical to calling scatter_element_add(np.zeros(new_dims), indices, array)
- Parameters
indices (tensor_like[int]) – Indices to update
array (tensor_like[float]) – Values to assign to the new tensor
new_dims (int or tuple[int]) – The shape of the new tensor
like (str) – Manually chosen interface to dispatch to.
- Returns
The tensor with the values modified the given indices.
- Return type
tensor_like[float]
Example
>>> indices = np.array([4, 3, 1, 7]) >>> updates = np.array([9, 10, 11, 12]) >>> shape = 8 >>> qml.math.scatter(indices, updates, shape) array([ 0, 11, 0, 10, 9, 0, 0, 12])
code/api/pennylane.math.scatter
Download Python script
Download Notebook
View on GitHub