Implementing a simple bivariate function using `numpy`

Viewed 16

I'm trying to implement the following simple bivariate function using numpy :

enter image description here

defined on a domain D = [-2,2] x [-2,2]

My attempt:

x = np.arange(-2,2, 0.01)
y = np.arange(-2,2,0.01)

import math

def fun(x,y):
    
    norm = np.sqrt(x**2 + y**2)
    
    mask = x <=2*y
    
    if x <= mask:
        
        return 2*math.sin(1.25*math.pi*norm)
    else:
        
        return 2*math.sin(0.75*math.pi*norm)

I understand that the problem is related to the if statement, since building the mask will provide multiple boolean values instead of a single one. Nevertheless, I don't know how I should circumvent such issue.

0 Answers
Related