【问题标题】:How can I replace a certain area of an 2D numpy array? [duplicate]如何替换 2D numpy 数组的某个区域? [复制]
【发布时间】:2021-02-01 17:58:33
【问题描述】:
X2d = np.array([[255,255,255,255],
                [255,255,255,255],
                [255,255,255,255],
                [255,255,255,255]])


# I want to give it information about right, up, width, height where I want to manipulate it
# for example (1, 1, 2, 2)
# and I would like to get these two:

X2dresult = np.array([[255,255,255,255],
                      [255,  0,  0,255],
                      [255,  0,  0,255],
                      [255,255,255,255]])

我想在更高的维度上做类似的事情。

【问题讨论】:

标签: python arrays image numpy image-processing


【解决方案1】:

你可以在 numpy.例如:

X2d = np.array([[255,255,255,255],
                [255,255,255,255],
                [255,255,255,255],
                [255,255,255,255]])

X2d[1:3, 1:3] = 0

给你:

array([[255, 255, 255, 255],
       [255,   0,   0, 255],
       [255,   0,   0, 255],
       [255, 255, 255, 255]])

这也适用于更高的维度。

【讨论】:

    猜你喜欢
    • 2019-08-05
    • 1970-01-01
    • 2022-01-07
    • 2018-12-28
    • 2019-09-12
    • 2012-06-08
    • 2016-06-10
    • 2014-10-09
    • 2016-02-15
    相关资源
    最近更新 更多