np.put(a, ind, v, mode=‘raise’)
参数解释:
Parameters:
a : ndarray
Target array.
ind : array_like
Target indices, interpreted as integers.
v : array_like
Values to place in a at target indices. If v is shorter than ind it will be repeated as necessary.
mode : {‘raise’, ‘wrap’, ‘clip’}, optional
Specifies how out-of-bounds indices will behave.
‘raise’ – raise an error (default)
‘wrap’ – wrap around
‘clip’ – clip to the range
‘clip’ mode means that all indices that are too large are replaced by the index that addresses the last element along that axis. Note that this disables indexing with negative numbers. In ‘raise’ mode, if an exception occurs the target array may still be modified.(“clip”模式意味着所有太大的索引都将替换为沿该轴寻址最后一个元素的索引。)
表示对数组中指定的索引值指向的元素替换成指定的值。索引在扁平的目标数组上工作
例子:
a = np.array([0,5,6,75,6])
np.put(a, [0,