#列表使用remove函数出现奇怪的报错
使用列表储存numpy数组时,出现只能remove第一个数组,不能移除其他的。同样都是numpy数组。
##示例代码
k = [np.array([10, 10]), np.array([9, 7])]
print(k[0],type(k[0]))
print(k[1],type(k[1]))
k.remove(k[1])
print(k)
##输出结果
[10 10] <class 'numpy.ndarray'>
[9 7] <class 'numpy.ndarray'>
Traceback (most recent call last):
File "D:\python-learn\math\test01.py", line 47, in <module>
k.remove(k[1])
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
##如果改成remove k[0]就不报错
k = [np.array([10, 10]), np.array([9, 7])]
print(k[0],type(k[0]))
print(k[1],type(k[1]))
k.remove(k[0])
print(k)
##正常输出
[10 10] <class 'numpy.ndarray'>
[9 7] <class 'numpy.ndarray'>
[array([9, 7])]
感觉就很莫名其妙,同样都是存的numpy数组,为啥第一个就可以remove,其他的就不行!