Q:

Doing conditional operations using meshgrids in numpy and merging them?

I have two variables, x,y. I want to calculate a group of secondary variables, based on conditions applied over all possible combinations of (x,y) pairs.
My final goal is to generate surface plots with these variables over the x,y grid.
For example, considering the conditions below:

A if $(x > y*\sqrt( (4*y) + 1)) AND (y < x*\sqrt( (4*x)+1) $
B if $(x < y*\sqrt( (4*y) + 1)) AND (y > x*\sqrt( (4*x)+1) $
C if $(x < y*\sqrt( (4*y) + 1)) AND (y < x*\sqrt( (4*x)+1) $
D, if  $x = y$

With (x,y) in [1,5], where the set of results {A,B,C,D} would represent one of my intended secondary variables that I intend to plot.
My approach was to create a meshgrid of x and y, and then run the separate conditions. I ended with four separate grids. 
Specific question: how would I go around merging these four meshgrids into one, so I could do the surface plot?
General question: Does this approach makes sense? Is there a more streamlined or efficient approach, considering I will be dealing with x,y going from [1,10000+), and where the cases {A,B,C,D} would involve more algebra?
My attempt so far:
x  = np.arange(1, 6, 1) 
y = np.arange(1, 6, 1) 

xx, yy  = np.meshgrid(x, y)

case_a = np.where(np.logical_and((xx > yy *( (4*yy)/1+1)**(1/2)), (yy < xx *((4*xx)/1+1)**(1/2))), "A", "")
case_b = np.where(np.logical_and((xx < yy *( (4*yy)/1+1)**(1/2)), (yy > xx *((4*xx)/1+1)**(1/2))), "B", "") 
case_c = np.where(np.logical_and((xx < yy *( (4*yy)/1+1)**(1/2)), (yy < xx *((4*xx)/1+1)**(1/2))), "C", "")
case_d = np.where(xx == yy, "D", "")

PS: I am not sure how to implement latex code in this SE. 
Thanks in advance, 

A:

Create the conditions using masks:
ma = np.logical_and((xx > yy *( (4*yy)/1+1)**(1/2)), (yy < xx *((4*xx)/1+1)**(1/2)))
mb = np.logical_and((xx < yy *( (4*yy)/1+1)**(1/2)), (yy > xx *((4*xx)/1+1)**(1/2)))
mc = np.logical_and((xx < yy *( (4*yy)/1+1)**(1/2)), (yy < xx *((4*xx)/1+1)**(1/2)))
md = xx == yy
# case_a = np.where(ma, "A", "")

Then you can use np.select:
case = np.select([ma, mb, mc, md], ['a', 'b', 'c', 'd'])

