如何在数量的矩阵中删除矩阵?

发布于 2025-02-10 15:02:29 字数 327 浏览 3 评论 0原文

我有一个 numpy数组 arr_seg_labs具有以下形状:(1735,128,128)。 它包含1到10之间的像素掩模,还包含零和255(背景)。 我想删除不包含给定类别标识符(9)的那些(128,128)矩阵,并保留至少包含一个9的矩阵。 我为此做了一个蒙版(horse_mask),但是我不知道如何继续此线程来过滤此numpy数组

CAT_IDX_HORSE = 9
horse_mask = arr_seg_labs == CAT_IDX_HORSE

I have a numpy array arr_seg_labs which has the following shape: (1735, 128, 128).
It contains pixel masks between 1 and 10 and also contains zeros and 255 (background).
I want to remove those (128, 128) matrices which not contain the given category identifier (9) and to keep those which contain at least one 9.
I made a mask (horse_mask) for this, but I don't know how can I continue this thread to filter this numpy array

CAT_IDX_HORSE = 9
horse_mask = arr_seg_labs == CAT_IDX_HORSE

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

椵侞 2025-02-17 15:02:29

IIUC您可以使用口罩并索引为:

CAT_IDX_HORSE = 9
mask = (a == CAT_IDX_HORSE ).sum((1, 2))
result = a[mask != 0]

IIUC you can use masks and indexing as:

CAT_IDX_HORSE = 9
mask = (a == CAT_IDX_HORSE ).sum((1, 2))
result = a[mask != 0]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文