【问题标题】:Zero out portion of multidim numpy arraymultidim numpy 数组的归零部分
【发布时间】:2015-09-04 02:01:11
【问题描述】:

我有一个尺寸为 (200, 200, 3) 的 numpy 数组。它是一个 RGB 图像。

我还想将该图像的某个区域的 (xmin,ymin,xmax,ymax) 坐标设置为零。该区域在所有三个通道中都应为零。

我当然可以用循环来解决这个问题,但这会很浪费。

有没有一种简单的方法来使用 numpy 来屏蔽数组?

【问题讨论】:

    标签: python-2.7 image-processing numpy


    【解决方案1】:

    使用数组切片。如果xminxmaxyminymax 是要设置为零的数组区域的索引,则:

    a[xmin:xmax,ymin:ymax,:] = 0.
    

    【讨论】:

      猜你喜欢
      • 2012-01-28
      • 1970-01-01
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 2016-11-06
      • 2021-09-22
      • 1970-01-01
      • 2020-07-10
      相关资源
      最近更新 更多