Dec-01-2019, 02:10 PM
(This post was last modified: Dec-01-2019, 02:53 PM by DreamingInsanity.)
Thanks for the reply - the way you have done it is quite intriguing.
I sort of had a similar idea, but it was very fragmented.
This is as far as I got in the time I had:
Dream
I've worked some magic and compressed the function to a single line:
I am going to test it out in my full project because that will really make sure it is working correctly.
I sort of had a similar idea, but it was very fragmented.
This is as far as I got in the time I had:
def find_closest2(col, array2d): r,g,b = col[0], col[1], col[2] first_el = [i[0] for i in array2d] second_el = [i[1] for i in array2d] third_el = [i[2] for i in array2d]which is almost exactly what you did in this line:
for num, elm in enumerate(array2d):.
Dream
I've worked some magic and compressed the function to a single line:
def find_closest2(col, array2d): get_lowest = lambda rgb_vals: min([[abs(col[0]-elm[0]) + abs(col[1]-elm[1]) + abs(col[2]-elm[2]), num] for num, elm in enumerate(rgb_vals)], key=lambda x: x[0])[1] return array2d[get_lowest(array2d)]It is difficult to tell if it is working, however, it doesn't produce errors so that's a good sign.
I am going to test it out in my full project because that will really make sure it is working correctly.