Test if a numpy array is a member of a list of numpy arrays, and remove it from the list

前端 未结 3 1835
-上瘾入骨i
-上瘾入骨i 2021-01-18 16:01

When testing if a numpy array c is member of a list of numpy arrays CNTS:

import numpy as np

c = np.array([[[ 75, 763]],
                  


        
3条回答
  •  臣服心动
    2021-01-18 16:47

    Use del to delete the index of the list you want to remove.

    del CNTS[int(np.where(list(np.array_equal(row, c) for row in CNTS))[0])]
    
    CNTS
    
    [array([[[  78, 1202]],
    
            [[  63, 1202]],
    
            [[  63, 1187]],
    
            [[  78, 1187]]]), array([[[ 72, 742]],
    
            [[ 58, 742]],
    
            [[ 57, 741]],
    
            [[ 57, 727]],
    
            [[ 58, 726]],
    
            [[ 72, 726]]]), array([[[ 66, 194]],
    
            [[ 51, 194]],
    
            [[ 51, 179]],
    
            [[ 66, 179]]])]
    

提交回复
热议问题