前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >numpy.put()

numpy.put()

作者头像
狼啸风云
发布2022-07-27 10:46:34
6550
发布2022-07-27 10:46:34
举报
文章被收录于专栏:计算机视觉理论及其实现

numpy.put

numpy.put(a, ind, v, mode='raise')

Replaces specified elements of an array with given values.The indexing works on the flattened target array. put is roughly equivalent to:

代码语言:javascript
复制
a.flat[ind] = v

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.

  • ‘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.

See also

putmask, place

put_along_axis

Put elements by matching the array and the index arrays

Examples

代码语言:javascript
复制
>>> 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])
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-07-26,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • numpy.put
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档