title: Python and Numba for vectorized functions
body: <p>Good day, I'm writing a Python module for some numeric work. Since there's a lot of stuff going on, I've been spending the last few days optimizing code to improve calculations times.
  However, I have a question concerning Numba.
  Basically, I have a class with some fields which are numpy arrays, which I initialize in the following way:</p>
  
  <pre><code>def init(self):
      a = numpy.arange(0, self.max_i, 1)
      self.vibr_energy = self.calculate_vibr_energy(a)
  
  def calculate_vibr_energy(i):
      return numpy.exp(-self.harmonic * i - self.anharmonic * (i ** 2))
  </code></pre>
  
  <p>So, the code is vectorized, and using Numba's JIT results in some improvement. However, sometimes I need to access the calculate_vibr_energy function from outside the class, and pass a single integer instead of an array in place of i.
  As far as I understand, if I use Numba's JIT on the calculate_vibr_energy, it will have to always take an array as an argument.</p>
  
  <p>So, which of the following options is better:
  1) Create a new function calculate_vibr_energy_single(i), which will only take a single integer number, and use Numba on it too
  2) Replace all usages of the function that are similar to this one:</p>
  
  <pre><code>myclass.calculate_vibr_energy(1)
  </code></pre>
  
  <p>with this:</p>
  
  <pre><code>tmp = np.array([1])
  myclass.calculate_vibr_energy(tmp)[0]
  </code></pre>
  
  <p>Or are there other, more efficient (or at least, more Python-ic) ways of doing that?</p>