I'm trying to find a union of two 2d arrays based on the first column:
>>> x1
array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
>>> x2
array([[ 7, -1, -1],
[10, 11, 12]])
If two rows have a matching first value, I want the one from x2
. I.e. the union of the first column of x1[:, 0]
and x2[:, 0]
is [1, 4, 7, 10]
and I want the row [7, -1, -1]
from x2
, not [7, 8, 9]
from x1
. The expected result in this case is:
>>> res
array([[ 1, 2, 3],
[ 4, 5, 6],
[ 7, -1, -1],
[10, 11, 12]])
I see there is a possible solution for union of a 2D array here, where I get the result:
>>> res
array([[ 1, 2, 3],
[ 4, 5, 6],
[ 7, -1, -1],
[ 7, 8, 9],
[10, 11, 12]])
In this result, I wanted the row [7, 8, 9]
from x1
to be excluded. How could I do that?