【问题标题】:Replace an array values between the two indexes using numpy使用 numpy 替换两个索引之间的数组值
【发布时间】:2019-11-13 14:58:09
【问题描述】:

我有一个类似的数组,

[2200,0,0,200 ,200 ..... 100]

现在,在这里,我正在尝试使用索引替换值。

我想替换索引1 to 15 by 100 之间的值。 . 所以,并将其存储在同一个数组中。

谁能帮我解决这个问题?

【问题讨论】:

  • I want to replace the values between index 1 to 15 by 100. . So, and store it in a same array。这是什么意思?您想用 100 或 adding 100 或 subtracting 100 替换它们吗?另外,通过索引1,您是指第一个元素还是第二个元素?请记住,数组(在您的情况下是 list)是从 0 开始的。
  • arr[1:15] = 100 ?

标签: python python-3.x pandas numpy


【解决方案1】:

你试过了吗:

arr = np.array([2200,0,0,200 ,200 ..... 100])
arr[1:15] = 100

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-14
    • 1970-01-01
    • 2015-10-31
    • 1970-01-01
    • 1970-01-01
    • 2019-05-26
    • 2011-01-20
    • 2019-05-02
    相关资源
    最近更新 更多