Changes specific elements of one array by replacing from another array.
Set a.flat[n] = v[n] for all n in ind. If v is shorter than ind, it will repeat which is different than a[ind] = v.
Parameters: | a : array_like (contiguous)
ind : array_like
v : array_like
mode : {‘raise’, ‘wrap’, ‘clip’}, optional
* ‘raise’ – raise an error : * ‘wrap’ – wrap around : * ‘clip’ – clip to the range : |
---|
Notes
If v is shorter than mask it will be repeated as necessary. In particular v can be a scalar or length 1 array. The routine put is the equivalent of the following (although the loop is in C for speed):
ind = array(indices, copy=False)
v = array(values, copy=False).astype(a.dtype)
for i in ind: a.flat[i] = v[i]
Examples
>>> x = np.arange(5)
>>> np.put(x,[0,2,4],[-1,-2,-3])
>>> print x
[-1 1 -2 3 -3]