title: parsing a conditional from a string
body: <p>I have two numpy arrays a, b and a string of the form <code>s = &quot;1.5 * b if 2*a &gt; 7 else a + b&quot;</code></p>
  <p>I would like to create an array c, which will evaluate the string on the arrays in an efficient manner.</p>
  <p>Example of a desired behavior:</p>
  <pre><code>a = np.array([1, 4])
  b = np.array([3, 1])
  s = &quot;1.5 * b if 2*a &gt; 7 else a + b&quot;
  print(my_eval(a, b, s))
  
  [4, 1.5]
  </code></pre>
  <p>Was thinking of something like
  <code>f = np.vectorize(eval(s)); map(a, b, f)</code></p>
  <p>What's the best way to do it? The number of arrays in the expression can be larger (but bounded by something reasonable.</p>