我在Python中有两个列表,每个列表包含一个数组。例如
list1[0]
out: array([[ 1, 2, 3],[ 4, 5, 6], . . .]], dtype=float32)
list2[0]
out: array([[ 1, 5, 3],[ 4, 5, 6], . . .]], dtype=float32)
and list1[0][0]
out: array([ 1, 2, 3], dtype=float32)
and list2[0][0]
out: array([ 1, 5, 3], dtype=float32)
列表包含代表3d空间中线的点。我想检查这两个列表是否相同,即它们是否表示3d空间中的相同行。我已经尝试过all(),any(),set()等,但是这些函数在非数组包含列表上起作用。有任何想法吗?
比较两个列表的长度后,您可以迭代并使用NumPy的array_equal
函数:
using numpy as np
def listsEqual(list1, list2):
return len(list1) == len(list2) and np.all([np.array_equal(l1, l2) for l1, l2 in zip(list1, list2)])
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句