Getting index error while trying to extract value from numpy array

Thread Starter


Joined Jan 11, 2018
Here's the code
``    pim ='try.png').convert('RGB')
   im  = np.array(pim)

def closest(colors,color):
    colors = np.array(colors)
    color = np.array(color)
    distances = np.sqrt(np.sum((colors-color)**2,axis=2))
    index_of_smallest =
    smallest_distance = colors[index_of_smallest]
    return smallest_distance

closest_color = closest(im,color)
print(closest_color )

A,B,C = closest_color[1] ``

Whenever the the values of RGB in array is under 100 the code works fine but the moment any value exceed 100 it shows that indexerror . I have also realized that I get this error with images with multiple colours (pictures taken with camera) and it works fine with images created with softwares with 2 or 3 colours

And here's the error message

[[224 189 69]]

Traceback (most recent call last):

File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iie 
c_run/", line 31, in <module> start(fakepyfile, 
mainpyfile) File 
c_run/", line 30, in start exec(open 
(mainpyfile).read(), main _dict_) File "<string>", line 22, in 
<module> IndexError: index 1 is out of bounds for axis 0 
with size 1

[Program finished]