[SciPy-User] calculating intersection points in probability curves
Wed Mar 3 16:41:37 CST 2010
On Wed, Mar 3, 2010 at 16:13, Tim Michelsen <email@example.com> wrote:
> my mail seems to have been too theoretical.
> Below is some example code.
> How can I calculate the intersection point (coordinates) between
> 'distribution_curve' and 'limit_line'?
> Which functions could help me here?
For finding where a monotonically increasing sequence crosses a
particular value, use np.searchsorted() with the Y coordinate array
and the value. This gives you the index into the Y array. Use that
index on the X values to find the X value where it crosses. Depending
on how you are interpreting those points, you may want that value, or
the next one, or some weighted average of the two.
For two sequences that cross, again it depends a little on the
sequences themselves and on how you interpret the sequences. Are they
step functions, or would you draw line segments from point to point?
Are they monotonic? Do they have the same X values? Do they have the
same set of Y values? etc. You could cobble something together where
you evaluate "h(x) = f(x) - g(x)" (where f(x) and g(x) use interp1d on
the original datasets) on the set of X points that is the union of the
two sequences of X points from the two datasets. Then search for zero
crossings (there may be more than one).
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the SciPy-User