python - Most pythonic way to check if a 1-dimensional list is an element of a 2-dimensional list? -
python - Most pythonic way to check if a 1-dimensional list is an element of a 2-dimensional list? -
using python 2.7.6, have list of rgb colors, each list, ie.:
color_list = [ [0, 0, 0], [255, 0, 0]....[255, 255, 255] ] calling this:
color = [0, 0, 0] if color in color_list: # stuff elicits:
valueerror: truth value of array more 1 element ambiguous. utilize a.any() or a.all() i'm concerned doing error suggests, ie. color.any() or color.all() literally going go looking integers anywhere in color list. can think ways accomplish actual aims, intuition python has well-seen need coming , there's pythonic way accomplish it. lil' help?
i'm fail. color in above code numpy.ndarray
the error message you're seeing coming numpy.
this means either color numpy array, or color_list is, or color_list list of numpy arrays. if lists, code have worked.
color_list = [ [0, 0, 0], [255, 0, 0], [255, 255, 255] ] color = [0, 0, 0] color in color_list => true python python-2.7
Comments
Post a Comment