I am using the InterpolatedUnivariateSpline function from the scipy.interpolate library. I know that there exists a function the evaluate the derivative of the resulting spline. What I am interested in is the derivative of the log of the spline. Is there a way to calculate this directly? Oct 8, 2018 in Python 108 views

## 1 answer to this question.

```import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import InterpolatedUnivariateSpline
x = np.arange(1, 9)
y = np.sqrt(x)                                  # something to use as y-values
spl = InterpolatedUnivariateSpline(x, y)

logder = lambda x: spl.derivative()(x)/spl(x)   # derivative of log of spline

t = np.linspace(x.min(), x.max())
plt.plot(t, logder(t))
plt.show()``` Constructing a spline based on the logarithm of data is also a reasonable approach, but it is not the same thing as the logarithm of the original spline.

if you can define a function, depending on a spline, which can be differentiated by python (analytically)

Differentiating an arbitrary function analytically is out of scope for SciPy. In the above example, I had to know that the derivative of log(x) is 1/x; SciPy does not know that. SymPy is a library for symbolic math operations such as derivatives.

It's possible to use SymPy to find the derivative of a function symbolically and then turn it, using lambdify, into a callable function that SciPy or matplotlib, etc can use.

One can also work with splines in an entirely symbolic way using SymPy but it's slow. answered Oct 8, 2018 by
• 56,900 points

## what is the practical use of polymorphism in Python?

Polymorphism is the ability to present the ...READ MORE

## Use of "continue" in python

The break statement is used to "break" ...READ MORE

## In a list of dictionaries, how can I find the minimum calue in a common dictionary field.

There are several options. Here is a ...READ MORE

+1 vote

## Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

## how do i change string to a list?

suppose you have a string with a ...READ MORE

+1 vote

## how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

## how do i use the enumerate function inside a list?

can you give an example using a ...READ MORE