I have two Numpy arrays as follows:
>>> x
array([[0, 3, 3],
[3, 3, 3],
[0, 3, 3]])
>>> y
array([[0, 0, 0],
[0, 2, 2],
[0, 2, 2]])
Comparing x and y, I would like the comparison result to assign values based on the following conditions:
- If
xandyvalues are nonzero, assign the lower value - If
xoryare zero, assign the non zero value - If
xandyare zero, assign 0
So referring to the above example, I would like the result to be:
>>> result
array([[0, 3, 3],
[3, 2, 2],
[0, 2, 2]])
Note: the array size is variable. I only took a 3 x 3 array as an example. x and y will be of the same size though.
How can I do this replacement/assignment operation using Numpy?