Reputation: 133
I have two arrays:
values_arr = [[100,1], [20,5], [40,50]...[50,30]]
images_arr = [img1, img2, img3,...imgn]
Both the arrays are numpy arrays.
The values_arr and images_arr are in the same order. i.e
[100, 1] corresponds to img1
How do I get the image given the value of index?
index = [20,5]
In this case, I should get img2 given the value of index = [20,5].
Upvotes: 1
Views: 200
Reputation: 195
You can make a dict as
values_arr_tup = [tuple(i) for i in values_arr]
dict_ = {key:value for key,value in zip(values_arr_tup ,images_arr)}
then perform dict_[tuple(index)]
to get the image
Upvotes: 1
Reputation: 40491
You can use np.where
to extract the index of the item :
images_arr[np.where(values_arr == [20,5])[0][0]]
Upvotes: 1