简体   繁体   English

如何删除一个numpy矩阵数组中的矩阵?

[英]How to remove matrices in a numpy array of matrices?

I have a numpy array arr_seg_labs which has the following shape: (1735, 128, 128) .我有一个numpy 数组arr_seg_labs ,其形状如下: (1735, 128, 128) It contains pixel masks between 1 and 10 and also contains zeros and 255 (background).它包含 1 到 10 之间的像素掩码,还包含零和 255(背景)。 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我想删除那些不包含给定类别标识符 (9) 的 (128, 128) 矩阵,并保留那些至少包含一个 9 的矩阵。我为此制作了一个掩码 ( horse_mask ),但我不知道如何我继续这个线程来过滤这个 numpy 数组

CAT_IDX_HORSE = 9
horse_mask = arr_seg_labs == CAT_IDX_HORSE

IIUC you can use masks and indexing as: IIUC 您可以将掩码和索引用作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM