I am using np.meshgrid() to plot an scalar function: Z= f(X,Y).
I have no problems when f(X,Y) is defined by a single equation. However, when f(X,Y) is split in two or more equations, such as:
X, Y = np.meshgrid(x, y, sparse = True, indexing = 'ij')
Z = f1(X,Y), y1 < y <= y2
Z = f2(X,Y), y > y2
I have no idea how to extract the value of 'Y' from the meshgrid array in order to check it against y1 and y2 in the conditional statement. I have tried several ways, like the one below, to no avail:
row1, col1 = np.where(Y == y1)
row2, col2 = np.where(Y == y2)
if( Y > Y[row1][0] and Y <= Y[row2][0] ):
Z = f1(X, Y)
elif ( Y > Y[row2][0] ):
Z = f2(X, Y)
When I use arrays for the calculations of Z, the execution is really slow, at least 10 to 20 times slower, depending on the grid size, when compared with vectorization. Is it possible to apply vectorization in this case? how? Thanks!
