[SciPy-User] Return variable value by function value

Andy Wilson wilson.andrew.j@gmail....
Sat Aug 27 09:47:28 CDT 2011

If an approximation is good enough, you can use scipy.interpolate.interp1d
to get a function that returns interpolated values. Your example doesn't
quite work because 0.95 is out of the range of the initial input.

import numpy as np
import scipy.interpolate

x = np.arange(0,100)
y = np.sqrt(1 - x**2/10E+4)

interp_func = scipy.interpolate.interp1d(x, y, kind='quadratic')

new_x = 0.95
interp_y = interp_func(new_x)
actual_y = np.sqrt(1 - new_x**2/10E+4)

print "actual value: %s" % actual_y
print "interpolated value %s" % interp_y
print "difference: %s" % (actual_y - interp_y)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20110827/544ae7a2/attachment.html 

More information about the SciPy-User mailing list