performance - Speeding up an Euler numerical scheme in python -


let's have update scheme looks this:

import numpy np  n = 1000 dt = 0.01  x = np.zeros(n) x[0] = 0.5  in xrange(1, n):      rand = np.random.normal(loc=0.,scale=1.)      x[i] = x[i-1]*(1 + dt + np.sqrt(dt)*rand) 

what best strategy speeding code of form, current array element needs previous array element make calculation?

i attempting put vectorised form i'm bit stuck how use trailing array element update current one.

if there better solutions don't involve vectorisation i'm open too.

try this:

x = np.random.randn(1000) x += 1 x[0] = 0.5 y = np.cumprod(x) 

answer in y


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -