标签: python arrays element
我有一个随机元素的数组。我如何检查,所有元素是否相同? numpy.all可以吗?感谢
答案 0 :(得分:1)
您可以使用all:
all
if all(i == a[0] for i in a): #all the elements are the same pass
您也可以使用一套:
if len(set(a)) == 1: #all the elements are the same pass