I want to get hold of the positions in an array and want to extract the values in those positions from another array. I have two arrays:
Array_1 = (1, 0, 23, 4, 0, 0, 17, 81, 0, 10)
Array_2 = (11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
With
a, b = numpy.unique(Array_1)
I get the following: a contains the values and b the positions.
a = (1, 23, 4, 17, 81, 10)
b = (0, 2, 3, 6, 7, 9)
I want the values of Array_2 at the positions of Array_1. In other words, I want:
c = (11, 13, 14, 17, 18, 20)
How do I get hold of those values?
numpy.uniquewill return a sorted array of unique values, including the0. 2nd) To get the indices ofnp.unique, you have to use the keywordreturn_index=True.