'What's the fastest way to identify elements in one numpy array, and use the index to look up elements in a second array?
I have two arrays. The first being an array of IDs, and the second being values for for those ids. I am trying to looks up the values for each unique ID from array 1 based on the index of the matching arrays. The values are classified integers 1-16. My current attempt looks like:
for id in np.unique(ID_array):
temp_array = np.where(ID_array == id, 1, 0)
test_array = Value_array * temp_array
count_array = np.where(test_array != 0)
Test_data:
ID_array = np.random.randint(1,10,(5,5))
Value_array = np.random.randint(1,16,(5,5))
From there I am just determining the percent distribution of each value class for the unique IDS.
What I am wondering, is there a faster way to identify the matching values in the second array other than creating a Boolean mask?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
