I am writing a code which reads data from a text file. I load the data using numpy loadtxt and it could look like something like this:
import numpy as np
Shop_Products = np.array(['Tomatos', 'Bread' , 'Tuna', 'Milk', 'Cheese'])
Shop_Inventory = np.array([12, 6, 10, 7, 8])
I want to check some of the products I have:
Shop_Query = np.array(['Cheese', 'Bread']
Now I would like to find these "items" indeces in the Shop_Products array without doing a for loop and if checks.
I wondered if it could be done with any of the numpy methods: I thought of using a intercept1d to find the common items and then use searchsorted. However, I cannot sort my "Products" list since I do not want to loose the original sorting (for example I would use the indexes to directly look for the inventory of each product).
Any advice on the "pythonish" solution?