The wrong way to speed up your code with Numba

If your NumPy-based code is too slow, you can sometimes use Numba to
speed it up. Numba is a compiled language that uses the same syntax as
Python, and it compiles at runtime, so it’s very easy to write. And
because it re-implements a large part of the NumPy APIs, it can also
easily be used with existing NumPy-based code.

However, Numba’s NumPy support can be a trap: it can lead you to missing
huge optimization opportunities by sticking to NumPy-style code. So in
this article we’ll show an example of:

  • The wrong way to use Numba, writing NumPy-style full array transforms.
  • The right way to use Numba, namely for loops.

An example: converting color images to grayscale

Consider a color image encoded with red,

 

 

 

To finish reading, please visit source site