Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Shiuan, </p> <p>I am still investigating your problem, how ever a few notes:</p> <p>Instead of looping and appending to an array you could do:</p> <h1>select every nth element:</h1> <pre><code># inside IPython console: [2]: a=np.arange(0,10) In [3]: a[::2] # here we select every 2nd element. Out[3]: array([0, 2, 4, 6, 8]) </code></pre> <p>so instead of calcultating runga-kutta on all elements of m:</p> <pre><code>new_m = m[::20] # select every element of m. </code></pre> <p>now call your function like this:</p> <pre><code>def drawstaticplot(new_m,n, d_n, n_o): n=vector.rungekutta1(n, d_n) d_n=vector.rungekutta2(n, d_n, i) x1 = n[0] y1 = n[1] z1 = n[2] xarray.append(x1) yarray.append(y1) zarray.append(z1) ... </code></pre> <h1>about appending, and iterating over large data sets:</h1> <p><code>append</code> in general is slow, because it copies the whole array and then stacks the new element. Instead, you already know the size of n, so you could do:</p> <pre><code>def drawstaticplot(new_m,n, d_n, n_o): # create the storage based on n, # notice i assumed that rungekutta, returns n the size of new_m, # but you can change it. x,y,z = np.zeros(n.shape[0]),np.zeros(n.shape[0]), np.zeros(n.shape[0]) for idx, itme in enumerate(new_m): # notice the function enumerate, make it your friend! n=vector.rungekutta1(n, d_n) d_n=vector.rungekutta2(n, d_n, ite,) x1 = n[0] y1 = n[1] z1 = n[2] #if i%20==0: # we don't need to check for the 20th element, m is already filtered... xarray[idx] = n[0] yarray[idx] = n[1] zarray[idx] = n[2] # is the second loop necessary? if (((zarray[idx]-n_o)&gt;0) and ((zarray[j+1]-n_o)&lt;0)): print zarray[idx]-n_o,counter plotthetaphi(xarray[idx],yarray[idx],zarray[idx]) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload