May-30-2020, 09:25 AM
I have this function here which is an answer from a thread of mine a while ago.
I have a file named 'test.py', which looks like this:
I also have this exact same function, in a different file with a different name. The rgb, although a lot longer, is the exact same. When I say exact, I mean I printed the rgb array from the second file and copied and pasted into the test file.
Instead, when I run it in the second file I get:
(As I said, I have copied and pasted the rgb array from the second file into 'test.py' so if it was the array wouldn't 'test.py' also error?)
def find_closest(color, rgb): return rgb[np.argmin(np.abs(rgb - color).sum(axis=1))]This function finds the closest rgb value (color) in a 2D array of rgb values (rgb).
I have a file named 'test.py', which looks like this:
def find_closest(color, rgb): return rgb[np.argmin(np.abs(rgb - color).sum(axis=1))] color = array([139, 168, 190]) rgb = array([array([144, 157, 178]), array([144, 146, 153]), array([49, 52, 56]), array([92, 84, 69]), array([ 86, 121, 140]), array([170, 141, 107])]) print(find_closest(color, rgb))And when run, the output is:
Output:[144 157 178]
That is exactly what it is supposed to output.I also have this exact same function, in a different file with a different name. The rgb, although a lot longer, is the exact same. When I say exact, I mean I printed the rgb array from the second file and copied and pasted into the test file.
Instead, when I run it in the second file I get:
Error:ValueError: operands could not be broadcast together with shapes (1209,) (3,)
This is what's confusing me. There is no difference between the function, the RGB array, the color - there's no difference between anything so how come I am getting an error when I run my second file?(As I said, I have copied and pasted the rgb array from the second file into 'test.py' so if it was the array wouldn't 'test.py' also error?)