I have two NumPy arrays:
A = asarray(['4', '4', '2', '8', '8', '8', '8', '8', '16', '32', '16', '16', '32'])
B = asarray(['2', '4', '8', '16', '32'])
I want a function that takes A, B
as parameters, and returns the index in B
for each value in A
, aligned with A
, as efficiently as possible.
These are the outputs for the test case above:
indices = [1, 1, 0, 2, 2, 2, 2, 2, 3, 4, 3, 3, 4]
I've tried exploring in1d()
, where()
, and nonzero()
with no luck. Any help is much appreciated.
Edit: Arrays are strings.