Q:

Understanding Numba TypingError with jit nopython

I'm having trouble solving a (probably basic) Numba error, using @jit(nopython=True). It boils down to the minimal example below, which produces a TypingError (full logs below). If relevant, I'm using Python 3.6.10 and Numba v0.49.0.
The error happens at the d line creating the numpy array (if I remove d and return c, it works fine). How can I solve this?
from numba import jit
import numpy as np

n = 5
foo = np.random.rand(n,n)

@jit(nopython=True)
def bar(x):
    a = np.array([0,3,2])
    b = np.array([1,2,3])
    c = [x[i,j] for i,j in zip(a,b)]
    # print(c) # Un-commenting this line solves the issue‽ (per @Ethan's comment)
    d = np.array(c)
    return d

baz = bar(foo)

Full error follows:
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
<ipython-input-13-950d2be33d72> in <module>
     14     return d
     15 
---> 16 baz = bar(foo)
     17 print(baz)

~/miniconda3/envs/py3k/lib/python3.6/site-packages/numba/core/dispatcher.py in _compile_for_args(self, *args, **kws)
    399                 e.patch_message(msg)
    400 
--> 401             error_rewrite(e, 'typing')
    402         except errors.UnsupportedError as e:
    403             # Something unsupported is present in the user code, add help info

~/miniconda3/envs/py3k/lib/python3.6/site-packages/numba/core/dispatcher.py in error_rewrite(e, issue_type)
    342                 raise e
    343             else:
--> 344                 reraise(type(e), e, None)
    345 
    346         argtypes = []

~/miniconda3/envs/py3k/lib/python3.6/site-packages/numba/core/utils.py in reraise(tp, value, tb)
     77         value = tp()
     78     if value.__traceback__ is not tb:
---> 79         raise value.with_traceback(tb)
     80     raise value
     81 

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Invalid use of Function(<intrinsic range_iter_len>) with argument(s) of type(s): (zip(iter(array(int64, 1d, C)), iter(array(int64, 1d, C))))
 * parameterized
In definition 0:
    All templates rejected with literals.
In definition 1:
    All templates rejected without literals.
This error is usually caused by passing an argument of a type that is unsupported by the named function.
[1] During: resolving callee type: Function(<intrinsic range_iter_len>)
[2] During: typing of call at <ipython-input-13-950d2be33d72> (9)

File "<ipython-input-13-950d2be33d72>", line 9:
def bar(x):
    a = np.array([0,3,2])
    ^

Update: Using the following function instead fails in a similar manner (though the print(c) trick does not help in this case):
@jit(nopython=True)
def bar(x):
    a = [0,3,2]
    b = [1,2,3]
    c = x[a, b]
    d = np.array(c)
    return d

A:

The problem with the first version of the function, and the fact that adding print(c) resolves it, is a mystery to me. Numba is supposed to implement zip (and obviously it can, in this exact case, when somehow triggered by the print(c) line), so this seems like a bug.
The problem with the second version of the function is less of a mystery. According to the current Numba documentation:

Arrays support normal iteration. Full basic indexing and slicing is supported. A subset of advanced indexing is also supported: only one advanced index is allowed, and it has to be a one-dimensional array (it can be combined with an arbitrary number of basic indices as well).

Since you're trying to use two advanced indices, a and b, in the line c = x[a, b], the code isn't supported by Numba. Indeed, that's what the wordy error message Invalid use of Function(<built-in function getitem>) with argument(s) of type(s): (array(float64, 2d, C), tuple(array(int64, 1d, C) x 2)) is saying. 
If we wrote c=x[a,2] instead, then the code would work, consistent with Numba's promise to allow one advanced index.
In general, I've found that the safest way to use Numba is to write in a loopy style without the more advanced features of NumPy. This is a bit unfortunate—since it's almost as if we need to write in a dialect of C rather than Python— but on the plus side it's still far more convenient than actually writing C.
In this vein, the following code works well:
@jit(nopython=True)
def bar(x):
    a = np.array([0,3,2])
    b = np.array([1,2,3])
    c = np.empty(len(a))
    for i in range(len(a)):
        c[i] = x[a[i], b[i]]
    return c

