原文:https://docs.scipy.org/doc/numpy/reference/generated/numpy.put.html
校对:(虚位以待)
numpy.
put
(a, ind, v, mode='raise')[source]用给定值替换数组的指定元素。
索引对展平的目标数组起作用。put
大致相当于:
a.flat[ind] = v
参数: | a:ndarray
ind:array_like
v:array_like
mode:{'raise','wrap','clip'},可选
|
---|
例子
>>> a = np.arange(5)
>>> np.put(a, [0, 2], [-44, -55])
>>> a
array([-44, 1, -55, 3, 4])
>>> a = np.arange(5)
>>> np.put(a, 22, -5, mode='clip')
>>> a
array([ 0, 1, 2, 3, -5])