# [SciPy-user] concave and convex function

josef.pktd@gmai... josef.pktd@gmai...
Sun May 17 02:32:17 CDT 2009

```On Fri, May 15, 2009 at 9:10 PM, mudit sharma <mudit_19a@yahoo.com> wrote:
>
> I have following sample (actual dataset is much bigger):
>
> [ 0.48  0.64  0.69  0.67  0.67  0.65  0.68  0.63  0.62  0.61  0.61  0.6
>  0.58  0.62  0.64  0.63  0.63  0.61  0.60  0.61  0.62  0.65  0.67  0.67
>  0.67  0.68  0.68  0.66  0.68  0.65  0.65  0.65  0.65  0.64  0.64  0.65
>  0.65  0.66  0.66  0.64  0.65  0.64  0.68  0.69  0.70   0.69  0.7   0.68
>  0.64  0.64  0.65  0.67  0.68  0.67  0.67  0.66  0.66  0.64  0.64  0.58
>  0.53  0.53  0.52]
>
>
> I am looking to scan for all M & W curve formation and cycles. For this I need to detect all concave and convex points on curve. Is there function available in scipy or mlab to fit data into concave and convex function? If there's any other straightforward way to achieve this, pleas suggest.
>

I'm not sure what you need, I don't know what M & W curve formation
and cycles are.

But for a 1d array, you can just check the second derivative with
np.diff, something like

x=np.linspace(0.,5.)
y = np.sin(x)
z=np.diff(np.diff(y))>0 # isconvex
z1=np.diff(y,2) # 2nd derivative
np.array(z1>0,int) -np.array(z1<0,int) # concave indicator

but your example array has lots of ups and downs. If it is a noisy
dataset, you might need to smooth it first?

Josef
```