python - Using a for loop to interchange maximum and mininum variables in an equation -


so have unpacked multiple arrays containing numbers in text file. i've figured out put them in equation so:

import numpy np import matplotlib.pyplot plt import urllib numpy import sin, cos scipy.special import jv  tms, period, perioderr, bjdo, bjdoerr, ecc, eccerr, omega, omegaerr, ampltd, ampltderr, yo, yoerr = np.loadtxt(tm_filename, unpack = true)  def compute_etv(bjd, bjdo, period, ecc, ampltd, omega, yo, numiter = 20):     m = 2 * np.pi * (bjd - bjdo) / period     u = m + sum([2./k * jv(k,k*ecc) * sin(k*m) k in range(1,numiter)])     return yo + ampltd/(24*60*60) * ((1-ecc**2)**0.5 * sin(u)*cos(omega)+(cos(u)-ecc)*sin(omega))  i,item in enumerate(tms[:10]):     etv = compute_etv(bjd[ecl==0], bjdo[i], period[i], ecc[i], ampltd[i], omega[i], yo[i], 20) 

the question is, "how can interchange minimum , maximum numbers of these values? want use loop input maximums , minimums each of arrays corresponding error value adding maximum or subtracting minimum, how can mix , match mins , maxs every combination possible?

edit

okay people don't find through mess of code, (it's terrible habit, since code...), i've thought of tl:dr version.

i have these arrays: m, x, , b. after this, have: m_error, x_error, , b_error. set min , max of these variables adding , subtracting error values of these original values.

m = np.arange(1, 10) x = np.arange(1, 10) b = np.arange(1, 10) m_error = np.linspace(0, 1, 9) x_error = np.linspace(0, 1, 9) b_error = np.linspace(0, 1, 9) m_max = m + m_error m_min = m - m_error x_max = x + x_error x_min = x - x_error b_max = b + b_error b_min = b - b_error   def compute(m, x, b):     y = m*x + b     return y 

how can put in loop gives me y for: "m_min(x_min) + b_min", "m(x_min) + b_min", "m(x) + b(min)", "m(x) + b", "m_max(x) + b"... , on?

you can find possible permutations find numerical solutions executing strings; it's hacky, if need better solution can repost question , wait on reply (assuming better solution exists!).

example:

m = 1 x = 2 b = 3 m_max = 4 m_min = 5 x_max = 6 x_min = 7 b_max = 8 b_min = 9  import parser  m_iters = ['m','m_max','m_min'] x_iters = ['x','x_max','x_min'] b_iters = ['b','b_max','b_min'] h =[] =[]  [h.append([k+'*'+j]) k in m_iters j in x_iters]     #m*x   perms [i.append(k+[v v in b_iters]) k in h]               #m*x+b perms  k in range(1,4):     j in i:         q = j[0]+'+'+j[k]         ans_q = eval(parser.expr(j[0]+'+'+j[k]).compile())  #eqn str         print q, '=', ans_q  >>> m*x+b = 5 m*x_max+b = 9 m*x_min+b = 10 m_max*x+b = 11 m_max*x_max+b = 27 m_max*x_min+b = 31 m_min*x+b = 13 m_min*x_max+b = 33 m_min*x_min+b = 38 m*x+b_max = 10 m*x_max+b_max = 14 m*x_min+b_max = 15 m_max*x+b_max = 16 m_max*x_max+b_max = 32 m_max*x_min+b_max = 36 m_min*x+b_max = 18 m_min*x_max+b_max = 38 m_min*x_min+b_max = 43 m*x+b_min = 11 m*x_max+b_min = 15 m*x_min+b_min = 16 m_max*x+b_min = 17 m_max*x_max+b_min = 33 m_max*x_min+b_min = 37 m_min*x+b_min = 19 m_min*x_max+b_min = 39 m_min*x_min+b_min = 44 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -