【问题标题】:Multidimensional indexing in numpy arraynumpy数组中的多维索引
【发布时间】:2021-01-16 18:10:08
【问题描述】:

假设我有一张这样的图片

image.shape=(280,280,3)

如果我做img[[[1,2],[1,2],[1,2]]].shape,我得到(2,)。但我希望获得(2,2,2)...

如何在numpy中同时对多个维度进行切片?

【问题讨论】:

    标签: numpy numpy-ndarray


    【解决方案1】:

    当您可能需要切片时,您正在使用 Array of Indices 语法。

    试试这样的:

    img[1:3, 1:3, 1:3]
    

    【讨论】:

    • 这正是我想要的。非常感谢。
    猜你喜欢
    • 2015-04-19
    • 1970-01-01
    • 1970-01-01
    • 2013-06-05
    • 1970-01-01
    • 2020-03-25
    • 2019-01-04
    • 2018-01-22
    • 2015-02-20
    相关资源
    最近更新 更多