title: Solve a non-linear equation within a loop on python
body: <p>I need some help to write my code more efficiently. The below code aims to solve a non-linear equation for a variable <code>hi</code> given the elements in some arrays. For example: </p>
  
  <pre><code>import numpy  as np 
  import tensorflow as tf
  import scipy.optimize 
  
  kon = 0.01
  mu  = 1.5
  fi  = 0.5 
  kappa = 22
  
  n =100
  xs = tf.random.normal(shape=(n,), stddev=0.2)
  eps = tf.random.normal(shape=(n,), stddev=0.17)
  z = tf.sigmoid(tf.random.normal(shape=(n,), stddev=0.22))
  
  # non-linear equation to solve for leisure 
  def F(hi):
    return (mu/fi)*np.log(hi) -(1-mu)*kappa*(hi)**(1+(1/fi))-mu*(np.log(w*ei*xs)-np.log(kon))-np.log(ze)
  hvec = np.empty((0,))
  # leisure today 
  for ze,ei,xs in zip(z, eps, x0):
      ei=tf.exp(ei)
      xs=tf.exp(xs)
      htemp = scipy.optimize.newton_krylov(F, 0.5)
      hvec = np.append(hvec, htemp)   
  </code></pre>
  
  <p>Here, <code>z</code>,<code>eps</code>,<code>x0</code> are arrays of size <code>n</code> (e.g. <code>n=100</code>)</p>
  
  <p>Is there a more efficient way to do the same thing? for example, by avoiding the loop ? </p>
  
  <p>I basically want to solve for <code>hi</code> for each element in these three arrays.</p>