python, list compare, ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() -
here python code:
def ava_check(nodes_group,child_list): ava_list=nodes_group[:] if nodes_group[1] in child_list: return none else: in nodes_group: if in child_list: ava_list.remove(a) ava_list.remove(nodes_group[nodes_group.index(a)-1]) else: pass
the nodes_group
list [0.0, (0, 3), 0.0, (0, 2), 0.0, (1, 3)]
. child_list
list [(0, 1)]
.
but when run code, there error: valueerror: truth value of array more 1 element ambiguous. use a.any() or a.all()
happened in line if in child_list:
. have no idea problem here. tried search, said numpy. didn't use numpy here, 2 inout arguments list tuples.
could me problem?
thanks much.
update: everyone's solution. data (not tuples) in list nodes_group numpy
array. store data in new list. checked data type of element in new list using type(), , found type numpy.float64
, explains why have error. write loop change type of element in list numpy.float64
int using int()
. problem solved. know whether better solution or more pythonic way? thanks.
one (or more) of values in nodes_group
list numpy
array, not float or tuple show in example data. can't use test a in some_list
if a
array, because array's ==
operator doesn't return bool
value, rather boolean array. boolean array raises exception see when python tries covert single bool
.
Comments
Post a Comment