I have a numpy structured array
import numpy as np
arr1 = (np.array([2, 5, 8, 3, 10], dtype=np.int64),np.array([10, 10, 10, 8, 3], dtype=np.int64))
arr1_x = arr1[0]
arr1_y = arr1[1]
arr1_struct = np.empty(arr1_x.shape[0], dtype=[('x', int), ('y', int)])
arr1_struct["x"] = arr1_x
arr1_struct["y"] = arr1_y
As you can see, in the above structured array, I have x and y values. I would need to do the following
- Check if there are multiple y values that are the same
- If there are, then I would need to keep only one x,y value pair for that y value.
- The x value to keep would need to be the smallest x value among the several x values corresponding to the y value in question
- x,y pairs are unique and not repeated
In the above example, I would need to keep:
- x = 2 and y = 10 (chosen from the three y=10 values)
- x = 3 and y = 8
- x = 10 and y = 3
The following would need to be discarded:
- x = 5 and y = 10
- x = 8 and y = 10
Is there a good way to go about this in numpy?