This is a very simple task, but somehow, I can't seem to figure it out.
Let's say I have a dictionary
dictr = {(0,1,2): 0, (5,4,2):1}
And an array:
A = [[0, 1, 2], [5, 4, 2]]
I am looking to get an array b = [0, 1]
I thought we could do it by:
B = np.vectorize(dictr.get)(A)
However, this is not working. Anyone knows why?
np.vectorizepasses scalar elements ofAtoget, not pairs or tuples. Sometimesvectorizeis convenient, but it does not help with speed. And often it is hard to use correctly.