As part of a more complicated function that I want to compile with
numba, I have to index an array A with another array idx.
Importantly, the dimension of the array A is variable.
The shape can be (N), (N,N), or (N,N,N) etc.
In python, I can do so using tuples:
def test():
A = np.arange(5*5*5).reshape(5,5,5)
idx = np.array([0,2,4])
return A[tuple(idx)]
However, indexing an array with a tuple is apparently not supported by numba since I get the following error:
TypingError: Failed in nopython mode pipeline (step: nopython frontend)
No implementation of function Function(<class 'tuple'>) found for signature:
>>> tuple(array(int64, 1d, C))
Note that this is just a minimal working example. In general, I do not
know the length of idx.
I thought of reshaping A to a vector and converting
idx to a corresponding scalar index.
Is that the best solution or is there a simple "numba alternative" to indexing with a tuple?