I just started to learn Numpy (and Scipy). I wrote a program to compute plot points for an f(x) function. (f(x) can't be given explicitly as I have to numerically solve an equation for each point.) I put the values in a 2D array:
[[x1, x2, x3, ...],
[f(x1), f(x2), f(x3), ...]]
My aim is now to find the maxima of the f(x) function, and get both it's location xm and it's value f(xm). Of course I could easily do this, but this seems to be something NumPy surely has a simple function. The only thing I found is numpy.amax, but it only returns the maximum value at each axis. (e.g. numpy.amax([[1, 3, 2],[5, 7, 9]], axis=1) returns [3, 9].).
I have two questions:
Did I took the good approach on storing the data points, or is there a specific object in NumPy/SciPy to do this?
Is there a built-in NumPy/SciPy function to find the maxima of my dataset?
This is the part of the code in question:
def get_max(args): ti_0 = sp.pi / 2.0 + 1E-10 ti_max = sp.pi - 1E-10 iters = 10000 step = (ti_max - ti_0) / iters ti = ti_0 result = np.empty((2, iters), float_) #the dataset, aim is to find the point where ret_energy is maximal for i in range(0, iters): tret = find_return_time(x, ti) ret_energy = ekin(tret, ti) ret_time = tret / sp.pi result[i, 0] = ret_time result[i, 1] = ret_energy ti += step emax = None #emax = find_maximal_return_energy(result) #-> ??? return emax