I have two arrays of randomly generated x's and y's and I want to evaluate each pair at some function. How do I do that using numpy? I tried the code below, but it does not work.
What I want is an array of func(x_i,y_i).
x = np.random.uniform(0, 1, 100)
y = np.random.uniform(0, 1, 100)
func = np.array((math.exp(-2 * x) * math.cos(2 * y)))
Any ideas?
np.array? or themath.cos(...)?numpybasics. Thinking in terms of evaluating single values or pairs as yourmathfunction requires, results in slow code. You want to become familiar with the operators and methods that work with whole arrays. The switch frommath.costonp.cosis just one example.