python list remove Use a.any() or a.all()

如果想删除一个numpy list中的元素,直接使用remove是不行的,会出错:

The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

所以,需要自己写一个函数

https://stackoverflow.com/questions/3157374/how-do-you-remove-a-numpy-array-from-a-list-of-numpy-arrays

参考上面链接

 

def removearray(L,arr):
    ind = 0
    size = len(L)
    while ind != size and not np.array_equal(L[ind],arr):
        ind += 1
    if ind != size:
        L.pop(ind)

 

 

你可能感兴趣的:(编程问题)