I want to map one numpy array to another one. My frist array has two columns and thousands of rows:
arr_1 = [[20, 0.5],
[30, 0.75],
[40, 1.0],
[50, 1.25],
[60, 1.5],
[70, 1.75],
...]
The second array can have a different number of rows and columns:
arr_2 = [[1, 0.45],
[2, 0.57],
[4, 0.58],
[1, 1.69],
[1, 1.51],
[1, 0.95],
...]
I want to compare the values of the second column of arr_2 with the second column of arr_1 to know which row of arr_2 is closer to which row of arr_1. Then I want to copy the first column of arr_1 into arr_2 from the row with the nearest second column.
For example, 0.45 in arr_2 is closest to 0.5, i.e. first row in arr_1. After finding that, I want to copy the first column of that row (which is 20) into arr_2. The final result would look something like:
arr_2_final = [[1, 0.45, 20],
[2, 0.57, 20],
[4, 0.58, 20],
[1, 1.69, 70],
[1, 1.51, 60],
[1, 0.95, 40],
...]