On Wed, Mar 14, 2012 at 8:34 AM, Laurent <[email protected]> wrote:
> #! /usr/bin/sage -python
> # -*- coding: utf8 -*-
>
> from sage.all import *
> from scipy import stats
> import numpy
>
> X=stats.norm.rvs(size=300)
> K=((heaviside(x+1)-heaviside(x-1))).function(x)
>
> f = sum( [ K( (Xi-x) ) for Xi in X ] )
> print f
>
> pts=numpy.linspace(0,3)
> for x in pts:
> print numerical_approx(f(x=x)) # One second each !
>
> Of course, each needs 600 calls to heaveside...
>
> An idea to speed up the process ?
Don't know whether you're still interested, but
the following should do the same thing slightly faster.
#! /usr/bin/python
# -*- coding: utf-8 -*-
from scipy import stats
import numpy as np
X=stats.norm.rvs(size=300)
def K(X0,x0):
a = (X0-x0)>-1
b = (X0-x0)<1
return sum(a*b)
pts=np.linspace(0,3)
for x in pts:
print K(X,x)
--
Vegard
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org