suppose i have a numpy array
A = [[1 2 3]
[2 3 3]
[1 2 3]]
and another array
B = [[3 2 3]
[1 2 3]
[4 6 3]]
and a array of true values:
C = [[1 4 3]
[8 7 3]
[4 10 3]]
Now I want to create an array D, the elements of which are dervied from either A or B, the condition being the closest value of each element from array C.
Is there any pythonic way to do this? Right now im using loops
>>> K = abs(A - C) < abs(B - C) # create array of bool
[[True, False, False],
[True, True, False],
[False, False, False]]
>>> D = where(K, A, B) # get elements of A and B respectively
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With